public class AnyMonads extends AsAnyMList
| Constructor and Description |
|---|
AnyMonads() |
| Modifier and Type | Method and Description |
|---|---|
static <U,R> java.util.function.Function<AnyM<U>,AnyM<R>> |
liftM(java.util.function.Function<U,R> fn)
Lift a function so it accepts a Monad and returns a Monad (simplex view of a wrapped Monad)
Simplex view simplifies type related challenges.
|
static <U1,U2,R> java.util.function.BiFunction<AnyM<U1>,AnyM<U2>,AnyM<R>> |
liftM2(java.util.function.BiFunction<U1,U2,R> fn)
Lift a function so it accepts a Monad and returns a Monad (simplex view of a wrapped Monad)
AnyM view simplifies type related challenges.
|
static <T1> AnyM<java.util.stream.Stream<T1>> |
sequence(java.util.Collection<AnyM<T1>> seq)
Convert a list of Monads to a Monad with a List
|
static <T1> AnyM<java.util.stream.Stream<T1>> |
sequence(java.util.stream.Stream<AnyM<T1>> seq) |
static <T,R> AnyM<java.util.List<R>> |
traverse(java.util.Collection<AnyM<T>> seq,
java.util.function.Function<T,R> fn)
Convert a list of Monads to a Monad with a List applying the supplied function in the process
|
static <T,R> AnyM<java.util.List<R>> |
traverse(java.util.stream.Stream<AnyM<T>> seq,
java.util.function.Function<T,R> fn) |
collectionToAnyMList, completableFutureToAnyMList, iterableToAnyMList, iteratorToAnyMList, notTypeSafeAnyMList, optionalToAnyMList, streamableToAnyMList, streamToAnyMListanyM, anyM, anyM, anyM, anyM, anyM, anyM, anyM, anyMFromBufferedReader, anyMFromCharSequence, anyMFromFile, anyMFromURL, anyMIterable, convertToAnyM, notTypeSafeAnyMpublic static <U,R> java.util.function.Function<AnyM<U>,AnyM<R>> liftM(java.util.function.Function<U,R> fn)
fn - public static <U1,U2,R> java.util.function.BiFunction<AnyM<U1>,AnyM<U2>,AnyM<R>> liftM2(java.util.function.BiFunction<U1,U2,R> fn)
BiFunction<AnyM<Integer>,AnyM<Integer>,AnyM<Integer>> add = Monads.liftM2(this::add);
Optional<Integer> result = add.apply(getBase(),getIncrease());
private Integer add(Integer a, Integer b){
return a+b;
}
The add method has no null handling, but we can lift the method to Monadic form, and use Optionals to automatically handle null / empty value cases.fn - BiFunction to liftpublic static <T,R> AnyM<java.util.List<R>> traverse(java.util.Collection<AnyM<T>> seq, java.util.function.Function<T,R> fn)
List<CompletableFuture<Integer>> futures;
AnyM<List<String>> futureList = Monads.traverse(CompletableFuture.class, futures, (Integer i) -> "hello" +i).anyM();
seq - List of Monadsfn - Function to applypublic static <T,R> AnyM<java.util.List<R>> traverse(java.util.stream.Stream<AnyM<T>> seq, java.util.function.Function<T,R> fn)
public static <T1> AnyM<java.util.stream.Stream<T1>> sequence(java.util.Collection<AnyM<T1>> seq)
List<CompletableFuture<Integer>> futures;
List<AnyM<Integer>> anyMs = anyMList(futures);
AnyM<List<Integer>> futureList = Monads.sequence(CompletableFuture.class, anyMs).anyM();
//where Simplex wraps CompletableFuture<List<Integer>>
seq - List of monads to convertfor helper methods to convert a List of Monads / Collections to List of AnyM