
com.github.valid8j.pcond.experimentals.currying.CurriedFunctions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of valid8j Show documentation
Show all versions of valid8j Show documentation
Java Library Providing Uniformed Programming Experiences across DbC, Value Checking, and Test Assertions
The newest version!
package com.github.valid8j.pcond.experimentals.currying;
import com.github.valid8j.pcond.core.printable.ParameterizedFunctionFactory;
import com.github.valid8j.pcond.core.printable.ParameterizedPredicateFactory;
import com.github.valid8j.pcond.core.printable.PrintablePredicateFactory;
import com.github.valid8j.pcond.experimentals.currying.context.CurriedContext;
import com.github.valid8j.pcond.experimentals.currying.context.CurriedContextUtils;
import com.github.valid8j.pcond.forms.Printables;
import com.github.valid8j.pcond.internals.InternalUtils;
import java.util.Collection;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static com.github.valid8j.pcond.internals.InternalUtils.formatObject;
/**
* A class that collects methods to create functions and predicates in experimental stage.
*/
public enum CurriedFunctions {
;
/**
* This function is used to construct a function which replaces 'nested loop' in a usual programming.
*
* @param inner A collection for the "inner loop".
* @return A function to construct a nested structure.
*/
public static Function, Stream> nest(Collection> inner) {
return Printables.function(() -> "nest" + InternalUtils.formatObject(inner), (Stream> stream) -> CurriedContextUtils.nest(stream, inner));
}
/**
* Returns a converter function for a stream.
* The function converts a stream of objects into and returns a stream of contexts each of which hols a value
* from the original stream.
*
* @return A function to convert an object stream into context stream.
* @see CurriedContext
*/
public static Function, Stream> toCurriedContextStream() {
return Printables.function(() -> "toCurriedContextStream", CurriedContextUtils::toCurriedContextStream);
}
/**
* Returns a function to convert a value into a context that holds the original value.
*
* @param The type of the original value.
* @return A function to convert a value into a context.
*/
public static Function toCurriedContext() {
return Printables.function(() -> "toCurriedContext", CurriedContextUtils::toCurriedContext);
}
/**
* Creates a context function that tests the value at the specified index using the given predicate.
*
* @param predicate_ A predicate with which the value is tested.
* @param argIndex An index to specify a value in the context.
* @param An expected type of value to be tested.
* @return A new predicate to test a value in a context.
*/
public static Predicate toCurriedContextPredicate(Predicate predicate_, int argIndex) {
return PrintablePredicateFactory.variableBundlePredicate(predicate_, argIndex);
}
/**
* Converts a predicate to a context predicate which tests the first value in a context
* using the `predicate`.
*
* @param predicate A predicate to be converted
* @param An expected type of the input value.
* @return A context predicate.
*/
public static Predicate toCurriedContextPredicate(Predicate predicate) {
return toCurriedContextPredicate(predicate, 0);
}
/**
* Converts a curried function which results in a boolean value into a predicate.
*
* @param curriedFunction A curried function to be converted.
* @param orderArgs An array to specify the order in which values in the context are applied to the function.
* @return A predicate converted from the given curried function.
*/
public static Predicate toCurriedContextPredicate(CurriedFunction
© 2015 - 2025 Weber Informatics LLC | Privacy Policy