T - MONAD - public interface Monad<MONAD,T> extends Functor<T>, Filterable<T>, Streamable<T>, AsGenericMonad
| Modifier and Type | Method and Description |
|---|---|
default <R> Monad<MONAD,R> |
aggregate(Monad<?,?> next)
Aggregate the contents of this Monad and the supplied Monad
List<Integer> result = monad(Stream.of(1,2,3,4)).<Integer>aggregate(monad(Optional.of(5))).toList();
assertThat(result,equalTo(Arrays.asList(1,2,3,4,5)));
|
default void |
allMatch(java.util.function.Predicate<T> c)
True if predicate matches all elements when Monad converted to a Stream
|
default void |
anyMatch(java.util.function.Predicate<T> c)
True if a single element matches when Monad converted to a Stream
|
default <NT,R> Monad<NT,R> |
applyM(Monad<?,java.util.function.Function<T,R>> fn)
Apply function/s inside supplied Monad to data in current Monad
e.g.
|
default <R> Monad<MONAD,T> |
bind(java.util.function.Function<T,R> fn)
Perform a looser typed flatMap / bind operation
The return type can be another type other than the host type
|
default <R,A> R |
collect(java.util.stream.Collector<T,A,R> collector)
Mutable reduction / collection over this Monad converted to a Stream
|
default java.util.List |
collect(java.util.stream.Stream<java.util.stream.Collector> collectors)
Apply multiple collectors Simulataneously to this Monad
List result = monad(Stream.of(1,2,3)).collect(Stream.of(Collectors.toList(),
Collectors.summingInt(Integer::intValue),
Collectors.averagingInt(Integer::intValue)));
assertThat(result.get(0),equalTo(Arrays.asList(1,2,3)));
assertThat(result.get(1),equalTo(6));
assertThat(result.get(2),equalTo(2.0));
NB if this Monad is an Optional [Arrays.asList(1,2,3)] reduce will operate on the Optional as if the list was one value
To reduce over the values on the list, called streamedMonad() first. |
default <R> Monad<java.util.stream.Stream<R>,R> |
cycle(java.lang.Class<R> monad,
int times)
Convert to a Stream, repeating the resulting structure specified times and
lifting all values to the specified Monad type
List<Optional<Integer>> list = monad(Stream.of(1,2))
.cycle(Optional.class,2)
.toList();
//is asList(Optional.of(1),Optional.of(2),Optional.of(1),Optional.of(2) ));
|
default Monad<java.util.stream.Stream<T>,T> |
cycle(int times)
Convert to a Stream with the values repeated specified times
|
default Monad<java.util.stream.Stream<T>,T> |
cycle(Monoid<T> m,
int times)
Convert to a Stream with the result of a reduction operation repeated specified times
List<Integer> list = AsGenericMonad,asMonad(Stream.of(1,2,2))
.cycle(Reducers.toCountInt(),3)
.collect(Collectors.toList());
//is asList(3,3,3);
|
default Monad<java.util.stream.Stream<T>,T> |
cycleUntil(java.util.function.Predicate<T> predicate)
Repeat in a Stream until specified predicate holds
|
default Monad<java.util.stream.Stream<T>,T> |
cycleWhile(java.util.function.Predicate<T> predicate)
Repeat in a Stream while specified predicate holds
|
default Monad<java.util.stream.Stream<T>,T> |
distinct() |
default Monad<MONAD,T> |
filter(java.util.function.Predicate<T> fn) |
default <NT,R> Monad<NT,R> |
filterM(Monad<?,java.util.function.Predicate<T>> fn)
Filter current monad by each element in supplied Monad
e.g.
|
default java.util.Optional<T> |
findAny() |
default java.util.Optional<T> |
findFirst() |
default <R extends MONAD,NT> |
flatMap(java.util.function.Function<T,R> fn)
flatMap operation
|
default <R> Monad<java.util.concurrent.CompletableFuture<R>,R> |
flatMapToCompletableFuture(java.util.function.Function<MONAD,java.util.concurrent.CompletableFuture<R>> fn) |
default <R> Monad<java.util.Optional<R>,R> |
flatMapToOptional(java.util.function.Function<MONAD,java.util.Optional<R>> fn) |
default <R> Monad<java.util.stream.Stream<R>,R> |
flatMapToStream(java.util.function.Function<MONAD,java.util.stream.Stream<R>> fn) |
default <T1> Monad<T,T1> |
flatten()
join / flatten one level of a nested hierarchy
|
default T |
foldLeft(Monoid<T> reducer) |
default <T> T |
foldLeftMapToType(Monoid<T> reducer)
Attempt to map this Monad to the same type as the supplied Monoid (using mapToType on the monoid interface)
Then use Monoid to reduce values
|
default T |
foldRight(Monoid<T> reducer) |
default <T> T |
foldRightMapToType(Monoid<T> reducer)
Attempt to map this Monad to the same type as the supplied Monoid (using mapToType on the monoid interface)
Then use Monoid to reduce values
|
default java.lang.Object |
getFilterable() |
default java.lang.Object |
getFunctor()
Override this method if you are using this class to wrap a Functor that does not
implement this interface natively.
|
java.lang.Object |
getMonad() |
default Monad<java.util.stream.Stream<java.util.List<T>>,java.util.List<T>> |
grouped(int groupSize)
Group elements in a Monad into a Stream
List<List<Integer>> list = monad(Stream.of(1,2,3,4,5,6))
.grouped(3)
.collect(Collectors.toList());
assertThat(list.get(0),hasItems(1,2,3));
assertThat(list.get(1),hasItems(4,5,6));
|
default <MONAD1,R> Monad<MONAD1,R> |
liftAndBind(java.util.function.Function<T,?> fn)
Perform a bind operation (@see #bind) but also lift the return value into a Monad using configured
MonadicConverters
|
default Monad<java.util.stream.Stream<T>,T> |
limit(int num)
NB to access nested collections in non-Stream monads as a stream use streamedMonad() first
assertThat(monad(Stream.of(4,3,6,7)).limit(2).toList(),equalTo(Arrays.asList(4,3))); |
default Monad<java.util.stream.Stream<T>,T> |
limitUntil(java.util.function.Predicate<T> p)
NB to access nested collections in non-Stream monads as a stream use streamedMonad() first
assertThat(monad(Stream.of(4,3,6,7)).limitUntil(i->i==6).toList(),equalTo(Arrays.asList(4,3))); |
default Monad<java.util.stream.Stream<T>,T> |
limitWhile(java.util.function.Predicate<T> p)
NB to access nested collections in non-Stream monads as a stream use streamedMonad() first
assertThat(monad(Stream.of(4,3,6,7)).sorted().limitWhile(i->i<6).toList(),equalTo(Arrays.asList(3,4))); |
default <R> Monad<MONAD,R> |
map(java.util.function.Function<T,R> fn) |
default <R> R |
mapReduce(java.util.function.Function<T,R> mapper,
Monoid<R> reducer)
Attempt to map this Monad to the same type as the supplied Monoid, using supplied function
Then use Monoid to reduce values
|
default <R> R |
mapReduce(Monoid<R> reducer)
Attempt to map this Monad to the same type as the supplied Monoid (using mapToType on the monoid interface)
Then use Monoid to reduce values
|
default <R,NT> Monad<R,NT> |
parallel() |
default Monad<MONAD,T> |
peek(java.util.function.Consumer<T> c) |
default java.util.List<T> |
reduce(java.lang.Iterable<Monoid<T>> reducers)
Reduce with multiple reducers in parallel
NB if this Monad is an Optional [Arrays.asList(1,2,3)] reduce will operate on the Optional as if the list was one value
To reduce over the values on the list, called streamedMonad() first.
|
default T |
reduce(Monoid<T> reducer)
NB if this Monad is an Optional [Arrays.asList(1,2,3)] reduce will operate on the Optional as if the list was one value
To reduce over the values on the list, called streamedMonad() first.
|
default java.util.List<T> |
reduce(java.util.stream.Stream<Monoid<T>> reducers)
Reduce with multiple reducers in parallel
NB if this Monad is an Optional [Arrays.asList(1,2,3)] reduce will operate on the Optional as if the list was one value
To reduce over the values on the list, called streamedMonad() first.
|
default <NT,R> Monad<NT,R> |
replicateM(int times)
Replicate given Monad
Simplex<Optional<Integer>> applied =monad(Optional.of(2)).replicateM(5).simplex();
assertThat(applied.unwrap(),equalTo(Optional.of(Arrays.asList(2,2,2,2,2))));
|
default Monad<java.util.stream.Stream<T>,T> |
scanLeft(Monoid<T> monoid)
Scan left using supplied Monoid
assertEquals(asList("", "a", "ab", "abc"),monad(Stream.of("a", "b", "c")).scanLeft(Reducers.toString("")).toList());
|
static <MONAD,T> Monad<MONAD,T> |
sequence(java.lang.Class c,
java.util.List<?> seq)
Convert a list of Monads to a Monad with a List
List<CompletableFuture<Integer>> futures;
Simplex<List<Integer>> futureList = Monad.sequence(CompletableFuture.class, futures).simplex();
|
static <MONAD,MONAD_LIST> |
sequenceNative(java.lang.Class c,
java.util.List<MONAD> seq)
Convert a list of Monads to a Monad with a List
List<CompletableFuture<Integer>> futures;
CompletableFuture<List<Integer>> futureList = Monad.sequence(CompletableFuture.class, futures);
|
default <X> Simplex<X> |
simplex() |
default Monad<java.util.stream.Stream<T>,T> |
skip(int num)
assertThat(monad(Stream.of(4,3,6,7)).skip(2).toList(),equalTo(Arrays.asList(6,7)));
NB to access nested collections in non-Stream monads as a stream use streamedMonad() first |
default Monad<java.util.stream.Stream<T>,T> |
skipUntil(java.util.function.Predicate<T> p)
NB to access nested collections in non-Stream monads as a stream use streamedMonad() first
assertThat(monad(Stream.of(4,3,6,7)).skipUntil(i->i==6).toList(),equalTo(Arrays.asList(6,7))); |
default Monad<java.util.stream.Stream<T>,T> |
skipWhile(java.util.function.Predicate<T> p)
NB to access nested collections in non-Stream monads as a stream use streamedMonad() first
assertThat(monad(Stream.of(4,3,6,7)).sorted().skipWhile(i->i<6).toList(),equalTo(Arrays.asList(6,7)));
|
default Monad<java.util.stream.Stream<java.util.List<T>>,java.util.List<T>> |
sliding(int windowSize)
Create a sliding view over this monad
|
default Monad<java.util.stream.Stream<T>,T> |
sorted() |
default Monad<java.util.stream.Stream<T>,T> |
sorted(java.util.Comparator<T> c)
Monad converted to Stream via stream() and sorted - to access nested collections in non-Stream monads as a stream use streamedMonad() first
e.g.
|
default boolean |
startsWith(java.lang.Iterable<T> iterable)
assertTrue(monad(Stream.of(1,2,3,4)).startsWith(Arrays.asList(1,2,3)));
|
default boolean |
startsWith(java.util.Iterator<T> iterator)
assertTrue(monad(Stream.of(1,2,3,4)).startsWith(Arrays.asList(1,2,3).iterator())) |
default java.util.stream.Stream<T> |
stream()
Unwrap this Monad into a Stream.
|
default <R,NT> Monad<R,NT> |
streamedMonad()
Transform the contents of a Monad into a Monad wrapping a Stream e.g.
|
default java.util.List<T> |
toList() |
default <T> java.util.Optional<T> |
toOptional() |
default java.util.Set<T> |
toSet() |
default <T> java.util.stream.Stream<T> |
toStream() |
default Streamable<T> |
toStreamable() |
static <MONAD,R> Monad<MONAD,java.util.List<R>> |
traverse(java.lang.Class c,
java.util.List<?> seq,
java.util.function.Function<?,R> fn)
Convert a list of Monads to a Monad with a List applying the supplied function in the process
List<CompletableFuture<Integer>> futures;
Simplex<List<String>> futureList = Monad.traverse(CompletableFuture.class, futures, (Integer i) -> "hello" +i).simplex();
|
static <MONAD,MONAD_LIST,R> |
traverseNative(java.lang.Class c,
java.util.List<MONAD> seq,
java.util.function.Function<?,R> fn)
Convert a list of Monads to a Monad with a List applying the supplied function in the process
List<CompletableFuture<Integer>> futures;
CompletableFuture<List<String>> futureList = Monad.traverse(CompletableFuture.class, futures, (Integer i) -> "hello" +i);
|
default <MONAD,T> MONAD |
unit(T value)
Generate a new instance of the underlying monad with given value
|
default MONAD |
unwrap() |
default Filterable<T> |
withFilterable(T filter) |
default <T> Monad<MONAD,T> |
withFunctor(T functor)
Will attempt to create a new instance of this functor type via constructor reflection
if this is a wrapped Functor (i.e.
|
<MONAD,T> Monad<MONAD,T> |
withMonad(java.lang.Object invoke) |
default <MONAD2,S,R> |
zip(Monad<MONAD2,? extends S> second,
java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
Generic zip function.
|
default <S,R> Monad<java.util.stream.Stream<R>,R> |
zip(java.util.stream.Stream<? extends S> second,
java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
Zip this Monad with a Stream
Stream<List<Integer>> zipped = asMonad(Stream.of(1,2,3)).zip(Stream.of(2,3,4),
(a,b) -> Arrays.asList(a,b));
//[[1,2][2,3][3,4]]
|
getStreamable, iterator, of<MONAD,T> Monad<MONAD,T> withMonad(java.lang.Object invoke)
java.lang.Object getMonad()
default <T> Monad<MONAD,T> withFunctor(T functor)
FunctorwithFunctor in interface Functor<T>default java.lang.Object getFunctor()
FunctorgetFunctor in interface Functor<T>default Filterable<T> withFilterable(T filter)
withFilterable in interface Filterable<T>default java.lang.Object getFilterable()
getFilterable in interface Filterable<T>default Monad<MONAD,T> filter(java.util.function.Predicate<T> fn)
filter in interface Filterable<T>default void allMatch(java.util.function.Predicate<T> c)
c - Predicate to check if all matchdefault void anyMatch(java.util.function.Predicate<T> c)
c - Predicate to check if any matchdefault java.util.Optional<T> findFirst()
default java.util.Optional<T> findAny()
default <R> Monad<MONAD,T> bind(java.util.function.Function<T,R> fn)
fn - flatMap functiondefault <MONAD1,R> Monad<MONAD1,R> liftAndBind(java.util.function.Function<T,?> fn)
fn - flatMap functiondefault <T1> Monad<T,T1> flatten()
default <R> R mapReduce(Monoid<R> reducer)
reducer - Monoid to reduce valuesdefault <R> R mapReduce(java.util.function.Function<T,R> mapper, Monoid<R> reducer)
mapper - Function to map Monad typereducer - Monoid to reduce valuesdefault <R,A> R collect(java.util.stream.Collector<T,A,R> collector)
collector - Collection operation definitiondefault java.util.List collect(java.util.stream.Stream<java.util.stream.Collector> collectors)
List result = monad(Stream.of(1,2,3)).collect(Stream.of(Collectors.toList(),
Collectors.summingInt(Integer::intValue),
Collectors.averagingInt(Integer::intValue)));
assertThat(result.get(0),equalTo(Arrays.asList(1,2,3)));
assertThat(result.get(1),equalTo(6));
assertThat(result.get(2),equalTo(2.0));
NB if this Monad is an Optional [Arrays.asList(1,2,3)] reduce will operate on the Optional as if the list was one value
To reduce over the values on the list, called streamedMonad() first. I.e. streamedMonad().collect(collectors);collectors - Stream of Collectors to applydefault T reduce(Monoid<T> reducer)
reducer - Use supplied Monoid to reduce valuesdefault java.util.List<T> reduce(java.util.stream.Stream<Monoid<T>> reducers)
reducers - default java.util.List<T> reduce(java.lang.Iterable<Monoid<T>> reducers)
reducers - default T foldLeft(Monoid<T> reducer)
reducer - Use supplied Monoid to reduce values starting via foldLeftdefault <T> T foldLeftMapToType(Monoid<T> reducer)
reducer - Monoid to reduce valuesdefault T foldRight(Monoid<T> reducer)
reducer - Use supplied Monoid to reduce values starting via foldRightdefault <T> T foldRightMapToType(Monoid<T> reducer)
reducer - Monoid to reduce valuesdefault Streamable<T> toStreamable()
default java.util.Set<T> toSet()
default java.util.List<T> toList()
default <T> java.util.stream.Stream<T> toStream()
default java.util.stream.Stream<T> stream()
stream in interface Streamable<T>default <T> java.util.Optional<T> toOptional()
Optional<List<T>> default <R> Monad<java.util.Optional<R>,R> flatMapToOptional(java.util.function.Function<MONAD,java.util.Optional<R>> fn)
default <R> Monad<java.util.stream.Stream<R>,R> flatMapToStream(java.util.function.Function<MONAD,java.util.stream.Stream<R>> fn)
default <R> Monad<java.util.concurrent.CompletableFuture<R>,R> flatMapToCompletableFuture(java.util.function.Function<MONAD,java.util.concurrent.CompletableFuture<R>> fn)
default Monad<java.util.stream.Stream<T>,T> cycle(int times)
times - Times values should be repeated within a Streamdefault Monad<java.util.stream.Stream<T>,T> cycle(Monoid<T> m, int times)
List<Integer> list = AsGenericMonad,asMonad(Stream.of(1,2,2))
.cycle(Reducers.toCountInt(),3)
.collect(Collectors.toList());
//is asList(3,3,3);
m - Monoid to be used in reductiontimes - Number of times value should be repeateddefault <R> Monad<java.util.stream.Stream<R>,R> cycle(java.lang.Class<R> monad, int times)
List<Optional<Integer>> list = monad(Stream.of(1,2))
.cycle(Optional.class,2)
.toList();
//is asList(Optional.of(1),Optional.of(2),Optional.of(1),Optional.of(2) ));
monad - times - default Monad<java.util.stream.Stream<T>,T> cycleWhile(java.util.function.Predicate<T> predicate)
predicate - repeat while truedefault Monad<java.util.stream.Stream<T>,T> cycleUntil(java.util.function.Predicate<T> predicate)
predicate - repeat while truedefault <MONAD2,S,R> Monad<java.util.stream.Stream<R>,R> zip(Monad<MONAD2,? extends S> second, java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
Stream<List<Integer>> zipped = asMonad(Stream.of(1,2,3)).zip(asMonad(Optional.of(2)),
(a,b) -> Arrays.asList(a,b));
// [[1,2]]
second - Monad to zip withzipper - Zipping functiondefault <S,R> Monad<java.util.stream.Stream<R>,R> zip(java.util.stream.Stream<? extends S> second, java.util.function.BiFunction<? super T,? super S,? extends R> zipper)
Stream<List<Integer>> zipped = asMonad(Stream.of(1,2,3)).zip(Stream.of(2,3,4),
(a,b) -> Arrays.asList(a,b));
//[[1,2][2,3][3,4]]
second - Stream to zip withzipper - Zip funcitondefault Monad<java.util.stream.Stream<java.util.List<T>>,java.util.List<T>> sliding(int windowSize)
windowSize - Size of sliding windowdefault Monad<java.util.stream.Stream<java.util.List<T>>,java.util.List<T>> grouped(int groupSize)
List<List<Integer>> list = monad(Stream.of(1,2,3,4,5,6))
.grouped(3)
.collect(Collectors.toList());
assertThat(list.get(0),hasItems(1,2,3));
assertThat(list.get(1),hasItems(4,5,6));
groupSize - Size of each Groupdefault boolean startsWith(java.lang.Iterable<T> iterable)
assertTrue(monad(Stream.of(1,2,3,4)).startsWith(Arrays.asList(1,2,3)));
iterable - default boolean startsWith(java.util.Iterator<T> iterator)
assertTrue(monad(Stream.of(1,2,3,4)).startsWith(Arrays.asList(1,2,3).iterator())) iterator - default Monad<java.util.stream.Stream<T>,T> scanLeft(Monoid<T> monoid)
assertEquals(asList("", "a", "ab", "abc"),monad(Stream.of("a", "b", "c")).scanLeft(Reducers.toString("")).toList());
monoid - default Monad<java.util.stream.Stream<T>,T> sorted()
monad(Optional.of(Arrays.asList(1,2,3))).sorted() // Monad[Stream[List[1,2,3]]]
monad(Optional.of(Arrays.asList(1,2,3))).streamedMonad().sorted() // Monad[Stream[1,2,3]]
assertThat(monad(Stream.of(4,3,6,7)).sorted().toList(),equalTo(Arrays.asList(3,4,6,7))); default Monad<java.util.stream.Stream<T>,T> sorted(java.util.Comparator<T> c)
monad(Optional.of(Arrays.asList(1,2,3))).sorted( (a,b)->b-a) // Monad[Stream[List[1,2,3]]]
monad(Optional.of(Arrays.asList(1,2,3))).streamedMonad().sorted( (a,b)->b-a) // Monad[Stream[3,2,1]]
c - Compartor to sort withdefault Monad<java.util.stream.Stream<T>,T> skip(int num)
assertThat(monad(Stream.of(4,3,6,7)).skip(2).toList(),equalTo(Arrays.asList(6,7)));
NB to access nested collections in non-Stream monads as a stream use streamedMonad() firstnum - Number of elemenets to skipdefault Monad<java.util.stream.Stream<T>,T> skipWhile(java.util.function.Predicate<T> p)
assertThat(monad(Stream.of(4,3,6,7)).sorted().skipWhile(i->i<6).toList(),equalTo(Arrays.asList(6,7)));
p - Predicate to skip while truedefault Monad<java.util.stream.Stream<T>,T> skipUntil(java.util.function.Predicate<T> p)
assertThat(monad(Stream.of(4,3,6,7)).skipUntil(i->i==6).toList(),equalTo(Arrays.asList(6,7)));p - Predicate to skip until truedefault Monad<java.util.stream.Stream<T>,T> limit(int num)
assertThat(monad(Stream.of(4,3,6,7)).limit(2).toList(),equalTo(Arrays.asList(4,3)));num - Limit element size to numdefault Monad<java.util.stream.Stream<T>,T> limitWhile(java.util.function.Predicate<T> p)
assertThat(monad(Stream.of(4,3,6,7)).sorted().limitWhile(i->i<6).toList(),equalTo(Arrays.asList(3,4)));p - Limit while predicate is truedefault Monad<java.util.stream.Stream<T>,T> limitUntil(java.util.function.Predicate<T> p)
assertThat(monad(Stream.of(4,3,6,7)).limitUntil(i->i==6).toList(),equalTo(Arrays.asList(4,3))); p - Limit until predicate is truedefault <NT,R> Monad<NT,R> applyM(Monad<?,java.util.function.Function<T,R>> fn)
Simplex<Integer> applied =monad(Stream.of(1,2,3)).applyM(monad(Streamable.of( (Integer a)->a+1 ,(Integer a) -> a*2))).simplex();
assertThat(applied.toList(),equalTo(Arrays.asList(2, 2, 3, 4, 4, 6)));
with Optionals
Simplex<Integer> applied =monad(Optional.of(2)).applyM(monad(Optional.of( (Integer a)->a+1)) ).simplex();
assertThat(applied.toList(),equalTo(Arrays.asList(3)));fn - default <NT,R> Monad<NT,R> filterM(Monad<?,java.util.function.Predicate<T>> fn)
Simplex<Stream<Integer>> applied = monad(Stream.of(1,2,3))
.filterM(monad(Streamable.of( (Integer a)->a>5 ,(Integer a) -> a<3)))
.simplex();
//results in Stream.of(Stream.of(1),Stream.of(2),Stream.of(())
fn - default <NT,R> Monad<NT,R> replicateM(int times)
Simplex<Optional<Integer>> applied =monad(Optional.of(2)).replicateM(5).simplex();
assertThat(applied.unwrap(),equalTo(Optional.of(Arrays.asList(2,2,2,2,2))));
times - number of times to replicatedefault <MONAD,T> MONAD unit(T value)
value - to construct new instance withstatic <MONAD,MONAD_LIST> MONAD_LIST sequenceNative(java.lang.Class c,
java.util.List<MONAD> seq)
List<CompletableFuture<Integer>> futures;
CompletableFuture<List<Integer>> futureList = Monad.sequence(CompletableFuture.class, futures);
c - The type of Monad to convertseq - List of monads to convertstatic <MONAD,MONAD_LIST,R> MONAD_LIST traverseNative(java.lang.Class c,
java.util.List<MONAD> seq,
java.util.function.Function<?,R> fn)
List<CompletableFuture<Integer>> futures;
CompletableFuture<List<String>> futureList = Monad.traverse(CompletableFuture.class, futures, (Integer i) -> "hello" +i);
c - Monad type to traverseseq - List of Monadsfn - Function to applystatic <MONAD,R> Monad<MONAD,java.util.List<R>> traverse(java.lang.Class c, java.util.List<?> seq, java.util.function.Function<?,R> fn)
List<CompletableFuture<Integer>> futures;
Simplex<List<String>> futureList = Monad.traverse(CompletableFuture.class, futures, (Integer i) -> "hello" +i).simplex();
c - Monad type to traverseseq - List of Monadsfn - Function to applystatic <MONAD,T> Monad<MONAD,T> sequence(java.lang.Class c, java.util.List<?> seq)
List<CompletableFuture<Integer>> futures;
Simplex<List<Integer>> futureList = Monad.sequence(CompletableFuture.class, futures).simplex();
c - The type of Monad to convertseq - List of monads to convertdefault <R> Monad<MONAD,R> aggregate(Monad<?,?> next)
List<Integer> result = monad(Stream.of(1,2,3,4)).<Integer>aggregate(monad(Optional.of(5))).toList();
assertThat(result,equalTo(Arrays.asList(1,2,3,4,5)));
next - Monad to aggregate content withdefault <R extends MONAD,NT> Monad<R,NT> flatMap(java.util.function.Function<T,R> fn)
fn - default <R,NT> Monad<R,NT> parallel()
default <R,NT> Monad<R,NT> streamedMonad()
Optional<List<Integer>> into Stream<Integer>
List<List<Integer>> list = monad(Optional.of(Arrays.asList(1,2,3,4,5,6)))
.<Stream<Integer>,Integer>streamedMonad()
.grouped(3)
.collect(Collectors.toList());
assertThat(list.get(0),hasItems(1,2,3));
assertThat(list.get(1),hasItems(4,5,6));
default <X> Simplex<X> simplex()
Monad<Stream<String>,String> becomes
Simplex<String>
To get back to Stream<String> use
simplex.<Stream<String>>.monad();