CurriedFunctions.java

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

Mutations

30

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

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

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

42

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

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

52

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

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

64

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

76

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

87

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

104

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

117

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

Active mutators

Tests examined


Report generated by PIT 1.7.3