CurriedFunctions.java

1
package com.github.valid8j.pcond.experimentals.currying;
2
3
import com.github.valid8j.pcond.core.printable.ParameterizedFunctionFactory;
4
import com.github.valid8j.pcond.core.printable.ParameterizedPredicateFactory;
5
import com.github.valid8j.pcond.core.printable.PrintablePredicateFactory;
6
import com.github.valid8j.pcond.experimentals.currying.context.CurriedContext;
7
import com.github.valid8j.pcond.experimentals.currying.context.CurriedContextUtils;
8
import com.github.valid8j.pcond.forms.Printables;
9
import com.github.valid8j.pcond.internals.InternalUtils;
10
11
import java.util.Collection;
12
import java.util.function.Function;
13
import java.util.function.Predicate;
14
import java.util.stream.Stream;
15
16
import static com.github.valid8j.pcond.internals.InternalUtils.formatObject;
17
18
/**
19
 * A class that collects methods to create functions and predicates in experimental stage.
20
 */
21
public enum CurriedFunctions {
22
  ;
23
24
  /**
25
   * This function is used to construct a function which replaces 'nested loop' in a usual programming.
26
   *
27
   * @param inner A collection for the "inner loop".
28
   * @return A function to construct a nested structure.
29
   */
30
  public static Function<Stream<?>, Stream<CurriedContext>> nest(Collection<?> inner) {
31 3 1. lambda$nest$0 : replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::lambda$nest$0 → KILLED
2. lambda$nest$1 : replaced return value with Stream.empty for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::lambda$nest$1 → KILLED
3. nest : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::nest → KILLED
    return Printables.function(() -> "nest" + InternalUtils.formatObject(inner), (Stream<?> stream) -> CurriedContextUtils.nest(stream, inner));
32
  }
33
34
  /**
35
   * Returns a converter function for a stream.
36
   * The function converts a stream of objects into and returns a stream of contexts each of which hols a value
37
   * from the original stream.
38
   *
39
   * @return A function to convert an object stream into context stream.
40
   * @see CurriedContext
41
   */
42
  public static Function<Stream<?>, Stream<CurriedContext>> toCurriedContextStream() {
43 2 1. lambda$toCurriedContextStream$2 : replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::lambda$toCurriedContextStream$2 → KILLED
2. toCurriedContextStream : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::toCurriedContextStream → KILLED
    return Printables.function(() -> "toCurriedContextStream", CurriedContextUtils::toCurriedContextStream);
44
  }
45
46
  /**
47
   * Returns a function to convert a value into a context that holds the original value.
48
   *
49
   * @param <T> The type of the original value.
50
   * @return A function to convert a value into a context.
51
   */
52
  public static <T> Function<T, CurriedContext> toCurriedContext() {
53 2 1. lambda$toCurriedContext$3 : replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::lambda$toCurriedContext$3 → KILLED
2. toCurriedContext : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::toCurriedContext → KILLED
    return Printables.function(() -> "toCurriedContext", CurriedContextUtils::toCurriedContext);
54
  }
55
56
  /**
57
   * Creates a context function that tests the value at the specified index using the given predicate.
58
   *
59
   * @param predicate_ A predicate with which the value is tested.
60
   * @param argIndex   An index to specify a value in the context.
61
   * @param <T>        An expected type of value to be tested.
62
   * @return A new predicate to test a value in a context.
63
   */
64
  public static <T> Predicate<CurriedContext> toCurriedContextPredicate(Predicate<T> predicate_, int argIndex) {
65 1 1. toCurriedContextPredicate : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::toCurriedContextPredicate → KILLED
    return PrintablePredicateFactory.variableBundlePredicate(predicate_, argIndex);
66
  }
67
68
  /**
69
   * Converts a predicate to a context predicate which tests the first value in a context
70
   * using the `predicate`.
71
   *
72
   * @param predicate A predicate to be converted
73
   * @param <T>       An expected type of the input value.
74
   * @return A context predicate.
75
   */
76
  public static <T> Predicate<CurriedContext> toCurriedContextPredicate(Predicate<T> predicate) {
77 1 1. toCurriedContextPredicate : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::toCurriedContextPredicate → KILLED
    return toCurriedContextPredicate(predicate, 0);
78
  }
79
80
  /**
81
   * Converts a curried function which results in a boolean value into a predicate.
82
   *
83
   * @param curriedFunction A curried function to be converted.
84
   * @param orderArgs       An array to specify the order in which values in the context are applied to the function.
85
   * @return A predicate converted from the given curried function.
86
   */
87
  public static Predicate<CurriedContext> toCurriedContextPredicate(CurriedFunction<Object, Object> curriedFunction, int... orderArgs) {
88 1 1. toCurriedContextPredicate : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::toCurriedContextPredicate → KILLED
    return CurriedContextUtils.toContextPredicate(curriedFunction, orderArgs);
89
  }
90
91
  /**
92
   * Returns a builder for a factory to create a predicate.
93
   * The factory accepts an argument to create a new predicate.
94
   * With this method, you can create predicates with different values.
95
   *
96
   * Suppose, you are about to create a predicate that tests a given string starts with `"hello"`.
97
   * At the same time, you also want to create a predicate that checks the value using `"こんにちは"`.
98
   * You can do it with the factory built by the returned value of this method.
99
   *
100
   * @param name The name of the predicate. It will be followed by the value passed to the factory in the `pcond`'s output.
101
   * @param <T>  The expected type of the value to be tested by the final predicate.
102
   * @return A builder to create a predicate factory.
103
   */
104
  public static <T> ParameterizedPredicateFactory.Builder<T> parameterizedPredicate(String name) {
105 1 1. parameterizedPredicate : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::parameterizedPredicate → KILLED
    return new ParameterizedPredicateFactory.Builder<T>().name(name);
106
  }
107
108
  /**
109
   * Returns a builder for a factory to create a function.
110
   *
111
   * @param name The name of the function. It will be followed by the value passed to the factory in the `pcond`'s output.
112
   * @param <T>  The expected type of the input value to the final function.
113
   * @param <R>  The expected type of the output value of the final function.
114
   * @return A builder to create a function factory.
115
   * @see CurriedFunctions#parameterizedPredicate(String)
116
   */
117
  public static <T, R> ParameterizedFunctionFactory.Builder<T, R> parameterizedFunction(String name) {
118 1 1. parameterizedFunction : replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::parameterizedFunction → KILLED
    return new ParameterizedFunctionFactory.Builder<T, R>().name(name);
119
  }
120
}

Mutations

31

1.1
Location : lambda$nest$0
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.given$hello$_$world$_whenRequireNestedStreamImpossibleConditions_thenPreconditionViolationExceptionWithCorrectMessage(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::lambda$nest$0 → KILLED

2.2
Location : lambda$nest$1
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.hello3(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
replaced return value with Stream.empty for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::lambda$nest$1 → KILLED

3.3
Location : nest
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.hello2(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::nest → KILLED

43

1.1
Location : lambda$toCurriedContextStream$2
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.givenStreamOfSingleString$hello$_whenRequireNullIsFound_thenPreconditionViolationWithCorrectMessageIsThrown(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::lambda$toCurriedContextStream$2 → KILLED

2.2
Location : toCurriedContextStream
Killed by : com.github.valid8j.ut.propertybased.tests.CurriedContextPredicateTest.exerciseTestCase[0: givenVariableBundlePredicate_whenExpectedValue_thenValueReturned](com.github.valid8j.ut.propertybased.tests.CurriedContextPredicateTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::toCurriedContextStream → KILLED

53

1.1
Location : lambda$toCurriedContext$3
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.givenString$hello$_whenTransformToContextAndCheckContextValueIsNull_thenPreconditionViolationWithCorrectMessageThrown(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
replaced return value with "" for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::lambda$toCurriedContext$3 → KILLED

2.2
Location : toCurriedContext
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.givenStreamOfSingleString$hello$_whenRequireNonNullIsFound_thenPassing(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::toCurriedContext → KILLED

65

1.1
Location : toCurriedContextPredicate
Killed by : com.github.valid8j.ut.experimentals.TestAssertionsCurriedFunctionsTest.toContextPredicateTest(com.github.valid8j.ut.experimentals.TestAssertionsCurriedFunctionsTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::toCurriedContextPredicate → KILLED

77

1.1
Location : toCurriedContextPredicate
Killed by : com.github.valid8j.ut.experimentals.TestAssertionsCurriedFunctionsTest.toContextPredicateTest(com.github.valid8j.ut.experimentals.TestAssertionsCurriedFunctionsTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::toCurriedContextPredicate → KILLED

88

1.1
Location : toCurriedContextPredicate
Killed by : com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest.performCurriedPredicate(com.github.valid8j.ut.experimentals.DbCCurriedFunctionsTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::toCurriedContextPredicate → KILLED

105

1.1
Location : parameterizedPredicate
Killed by : com.github.valid8j.ut.experimentals.TestAssertionsCurriedFunctionsTest.parameterizedPredicate_(com.github.valid8j.ut.experimentals.TestAssertionsCurriedFunctionsTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::parameterizedPredicate → KILLED

118

1.1
Location : parameterizedFunction
Killed by : com.github.valid8j.ut.experimentals.TestAssertionsCurriedFunctionsTest.parameterizedFunctionTest(com.github.valid8j.ut.experimentals.TestAssertionsCurriedFunctionsTest)
replaced return value with null for com/github/valid8j/pcond/experimentals/currying/CurriedFunctions::parameterizedFunction → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3