public class AnyMonads extends AsAnyMList
| Constructor and Description |
|---|
AnyMonads() |
| Modifier and Type | Method and Description |
|---|---|
static <U,R> java.util.function.Function<com.aol.cyclops.monad.AnyM<U>,com.aol.cyclops.monad.AnyM<R>> |
liftM(java.util.function.Function<U,R> fn)
Lift a function so it accepts an AnyM and returns an AnyM (any monad)
AnyM view simplifies type related challenges.
|
static <U1,U2,R> java.util.function.BiFunction<com.aol.cyclops.monad.AnyM<U1>,com.aol.cyclops.monad.AnyM<U2>,com.aol.cyclops.monad.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> com.aol.cyclops.monad.AnyM<java.util.stream.Stream<T1>> |
sequence(java.util.Collection<com.aol.cyclops.monad.AnyM<T1>> seq)
Convert a Collection of Monads to a Monad with a List
|
static <T1> com.aol.cyclops.monad.AnyM<java.util.stream.Stream<T1>> |
sequence(java.util.stream.Stream<com.aol.cyclops.monad.AnyM<T1>> seq)
Convert a Stream of Monads to a Monad with a List
|
static <T,R> com.aol.cyclops.monad.AnyM<java.util.List<R>> |
traverse(java.util.Collection<com.aol.cyclops.monad.AnyM<T>> seq,
java.util.function.Function<T,R> fn)
Convert a Collection of Monads to a Monad with a List applying the supplied function in the process
|
static <T,R> com.aol.cyclops.monad.AnyM<java.util.List<R>> |
traverse(java.util.stream.Stream<com.aol.cyclops.monad.AnyM<T>> seq,
java.util.function.Function<T,R> fn)
Convert a Stream of Monads to a Monad with a List applying the supplied function in the process
|
collectionToAnyMList, completableFutureToAnyMList, iterableToAnyMList, iteratorToAnyMList, notTypeSafeAnyMList, optionalToAnyMList, streamableToAnyMList, streamToAnyMListanyM, anyM, anyM, anyM, anyM, anyM, anyM, anyMFromBufferedReader, anyMFromCharSequence, anyMFromFile, anyMFromURL, anyMIterable, anyMList, anyMSet, convertToAnyM, notTypeSafeAnyMpublic static <U,R> java.util.function.Function<com.aol.cyclops.monad.AnyM<U>,com.aol.cyclops.monad.AnyM<R>> liftM(java.util.function.Function<U,R> fn)
fn - public static <U1,U2,R> java.util.function.BiFunction<com.aol.cyclops.monad.AnyM<U1>,com.aol.cyclops.monad.AnyM<U2>,com.aol.cyclops.monad.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> com.aol.cyclops.monad.AnyM<java.util.List<R>> traverse(java.util.Collection<com.aol.cyclops.monad.AnyM<T>> seq,
java.util.function.Function<T,R> fn)
List<CompletableFuture<Integer>> futures = createFutures();
AnyM<List<String>> futureList = AnyMonads.traverse(AsAnyMList.anyMList(futures), (Integer i) -> "hello" +i);
seq - Collection of Monadsfn - Function to applypublic static <T,R> com.aol.cyclops.monad.AnyM<java.util.List<R>> traverse(java.util.stream.Stream<com.aol.cyclops.monad.AnyM<T>> seq,
java.util.function.Function<T,R> fn)
Stream<CompletableFuture<Integer>> futures = createFutures();
AnyM<List<String>> futureList = AnyMonads.traverse(AsAnyMList.anyMList(futures), (Integer i) -> "hello" +i);
seq - Stream of Monadsfn - Function to applypublic static <T1> com.aol.cyclops.monad.AnyM<java.util.stream.Stream<T1>> sequence(java.util.Collection<com.aol.cyclops.monad.AnyM<T1>> seq)
List<CompletableFuture<Integer>> futures = createFutures();
AnyM<List<Integer>> futureList = AnyMonads.sequence(AsAnyMList.anyMList(futures));
//where AnyM wraps CompletableFuture<List<Integer>>
seq - Collection of monads to convertfor helper methods to convert a List of Monads / Collections to List of AnyMpublic static <T1> com.aol.cyclops.monad.AnyM<java.util.stream.Stream<T1>> sequence(java.util.stream.Stream<com.aol.cyclops.monad.AnyM<T1>> seq)
Stream<CompletableFuture<Integer>> futures = createFutures();
AnyM<List<Integer>> futureList = AnyMonads.sequence(AsAnyMList.anyMList(futures));
//where AnyM wraps CompletableFuture<List<Integer>>
seq - Stream of monads to convertfor helper methods to convert a List of Monads / Collections to List of AnyM