T - public class AnyMImpl<T>
extends java.lang.Object
implements com.aol.cyclops.monad.AnyM<T>
| Constructor and Description |
|---|
AnyMImpl() |
| Modifier and Type | Method and Description |
|---|---|
com.aol.cyclops.monad.AnyM<java.util.List<T>> |
aggregate(com.aol.cyclops.monad.AnyM<T> next)
Aggregate the contents of this Monad and the supplied Monad
|
<R> com.aol.cyclops.monad.AnyM<java.util.List<R>> |
aggregateUntyped(com.aol.cyclops.monad.AnyM<?> next) |
<R> com.aol.cyclops.monad.AnyM<R> |
applyM(com.aol.cyclops.monad.AnyM<java.util.function.Function<? super T,? extends R>> fn) |
<R> com.aol.cyclops.monad.AnyM<R> |
applyMCompletableFuture(java.util.concurrent.CompletableFuture<java.util.function.Function<? super T,? extends R>> fn) |
<R> com.aol.cyclops.monad.AnyM<R> |
applyMOptional(java.util.Optional<java.util.function.Function<? super T,? extends R>> fn) |
<R> com.aol.cyclops.monad.AnyM<R> |
applyMStream(java.util.stream.Stream<java.util.function.Function<? super T,? extends R>> fn) |
com.aol.cyclops.sequence.SequenceM<T> |
asSequence()
Wrap this Monad's contents as a Sequence without disaggreating it.
|
<R> com.aol.cyclops.monad.AnyM<R> |
bind(java.util.function.Function<? super T,?> fn)
Perform a looser typed flatMap / bind operation
The return type can be another type other than the host type
|
<R,A> R |
collect(java.util.stream.Collector<? super T,A,R> collector)
Collect the contents of the monad wrapped by this AnyM into supplied collector
|
<T> com.aol.cyclops.monad.AnyM<T> |
empty() |
com.aol.cyclops.monad.AnyM<T> |
filter(java.util.function.Predicate<? super T> fn) |
<R> com.aol.cyclops.monad.AnyM<R> |
flatMap(java.util.function.Function<? super T,com.aol.cyclops.monad.AnyM<? extends R>> fn)
flatMap operation
|
com.aol.cyclops.monad.AnyM<java.lang.String> |
flatMapBufferedReader(java.util.function.Function<? super T,java.io.BufferedReader> fn)
Perform a flatMap operation where the result will be a flattened stream of Strings
from the text loaded from the supplied BufferedReaders
|
com.aol.cyclops.monad.AnyM<java.lang.Character> |
flatMapCharSequence(java.util.function.Function<? super T,java.lang.CharSequence> fn)
Perform a flatMap operation where the result will be a flattened stream of Characters
from the CharSequence returned by the supplied function.
|
<R> com.aol.cyclops.monad.AnyM<R> |
flatMapCollection(java.util.function.Function<? super T,java.util.Collection<? extends R>> fn)
flatMapping to a Stream will result in the Stream being converted to a List, if the host Monad
type is not a Stream (or Stream like type).
|
<R> com.aol.cyclops.monad.AnyM<R> |
flatMapCompletableFuture(java.util.function.Function<? super T,java.util.concurrent.CompletableFuture<? extends R>> fn) |
com.aol.cyclops.monad.AnyM<java.lang.String> |
flatMapFile(java.util.function.Function<? super T,java.io.File> fn)
Perform a flatMap operation where the result will be a flattened stream of Strings
from the text loaded from the supplied files.
|
<R> com.aol.cyclops.monad.AnyM<R> |
flatMapOptional(java.util.function.Function<? super T,java.util.Optional<? extends R>> fn)
Convenience method to allow method reference support, when flatMap return type is a Optional
|
<R> com.aol.cyclops.monad.AnyM<R> |
flatMapSequenceM(java.util.function.Function<? super T,com.aol.cyclops.sequence.SequenceM<? extends R>> fn) |
<R> com.aol.cyclops.monad.AnyM<R> |
flatMapStream(java.util.function.Function<? super T,java.util.stream.BaseStream<? extends R,?>> fn)
Convenience method to allow method reference support, when flatMap return type is a Stream
|
<R> com.aol.cyclops.monad.AnyM<R> |
flatMapStreamable(java.util.function.Function<? super T,com.aol.cyclops.sequence.streamable.Streamable<R>> fn)
Convenience method to allow method reference support, when flatMap return type is a Streamable
|
com.aol.cyclops.monad.AnyM<java.lang.String> |
flatMapURL(java.util.function.Function<? super T,java.net.URL> fn)
Perform a flatMap operation where the result will be a flattened stream of Strings
from the text loaded from the supplied URLs
|
<T1> com.aol.cyclops.monad.AnyM<T1> |
flatten()
join / flatten one level of a nested hierarchy
|
void |
forEach(java.util.function.Consumer<? super T> action) |
<R1,R> com.aol.cyclops.monad.AnyM<R> |
forEach2(java.util.function.Function<? super T,? extends com.aol.cyclops.monad.AnyM<R1>> monad,
java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends R>> yieldingFunction) |
<R1,R> com.aol.cyclops.monad.AnyM<R> |
forEach2(java.util.function.Function<? super T,? extends com.aol.cyclops.monad.AnyM<R1>> monad,
java.util.function.Function<? super T,java.util.function.Function<? super R1,java.lang.Boolean>> filterFunction,
java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends R>> yieldingFunction) |
<R1,R2,R> com.aol.cyclops.monad.AnyM<R> |
forEach3(java.util.function.Function<? super T,? extends com.aol.cyclops.monad.AnyM<R1>> monad1,
java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends com.aol.cyclops.monad.AnyM<R2>>> monad2,
java.util.function.Function<? super T,java.util.function.Function<? super R1,java.util.function.Function<? super R2,? extends R>>> yieldingFunction) |
<R1,R2,R> com.aol.cyclops.monad.AnyM<R> |
forEach3(java.util.function.Function<? super T,? extends com.aol.cyclops.monad.AnyM<R1>> monad1,
java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends com.aol.cyclops.monad.AnyM<R2>>> monad2,
java.util.function.Function<? super T,java.util.function.Function<? super R1,java.util.function.Function<? super R2,java.lang.Boolean>>> filterFunction,
java.util.function.Function<? super T,java.util.function.Function<? super R1,java.util.function.Function<? super R2,? extends R>>> yieldingFunction) |
java.util.Iterator<T> |
iterator() |
<R> com.aol.cyclops.monad.AnyM<R> |
liftAndBind(java.util.function.Function<? super T,?> fn)
Perform a bind operation (@see #bind) but also lift the return value into a Monad using configured
MonadicConverters
|
<R> com.aol.cyclops.monad.AnyM<R> |
map(java.util.function.Function<? super T,? extends R> fn) |
Monad |
monad() |
com.aol.cyclops.monad.AnyM<T> |
peek(java.util.function.Consumer<? super T> c) |
com.aol.cyclops.monad.AnyM<T> |
reduceM(com.aol.cyclops.sequence.Monoid<com.aol.cyclops.monad.AnyM<T>> reducer) |
com.aol.cyclops.monad.AnyM<T> |
reduceMCompletableFuture(com.aol.cyclops.sequence.Monoid<java.util.concurrent.CompletableFuture<T>> reducer) |
com.aol.cyclops.monad.AnyM<T> |
reduceMIterable(com.aol.cyclops.sequence.Monoid<java.lang.Iterable<T>> reducer) |
com.aol.cyclops.monad.AnyM<T> |
reduceMOptional(com.aol.cyclops.sequence.Monoid<java.util.Optional<T>> reducer) |
com.aol.cyclops.monad.AnyM<T> |
reduceMStream(com.aol.cyclops.sequence.Monoid<java.util.stream.Stream<T>> reducer) |
com.aol.cyclops.monad.AnyM<T> |
reduceMStreamable(com.aol.cyclops.sequence.Monoid<com.aol.cyclops.sequence.streamable.Streamable<T>> reducer) |
com.aol.cyclops.monad.AnyM<java.util.List<T>> |
replicateM(int times) |
com.aol.cyclops.sequence.SequenceM<T> |
stream() |
java.util.List<T> |
toList() |
<T> com.aol.cyclops.sequence.SequenceM<T> |
toSequence()
Optional<List<Integer>> into Stream<Integer> |
<NT> com.aol.cyclops.sequence.SequenceM<NT> |
toSequence(java.util.function.Function<T,java.util.stream.Stream<NT>> fn)
Sequence the contents of a Monad.
|
java.util.Set<T> |
toSet() |
java.lang.String |
toString() |
<T> com.aol.cyclops.monad.AnyM<T> |
unit(T value) |
<R> R |
unwrap() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitfromArray, fromCollection, fromCompletableFuture, fromDoubleStream, fromFile, fromIntStream, fromIterable, fromList, fromLongStream, fromOptional, fromOptionalDouble, fromOptionalInt, fromOptionalLong, fromRange, fromRangeLong, fromSet, fromStream, fromStreamable, fromURL, liftM, liftM2, liftM2, liftM3, liftM3, liftM4, liftM4, liftM5, liftM5, listFromCollection, listFromCompletableFuture, listFromIterable, listFromIterator, listFromOptional, listFromStream, listFromStreamable, ofConvertable, ofMonad, ofMonadList, ofNullable, sequence, sequence, streamOf, toCompletableFuture, toOptional, traverse, traversepublic final <R> R unwrap()
unwrap in interface com.aol.cyclops.monad.AnyM<T>unwrap in interface com.aol.cyclops.sequence.Unwrapablepublic final <R,A> R collect(java.util.stream.Collector<? super T,A,R> collector)
collect in interface com.aol.cyclops.monad.AnyM<T>public final com.aol.cyclops.monad.AnyM<T> filter(java.util.function.Predicate<? super T> fn)
filter in interface com.aol.cyclops.monad.AnyM<T>public final <R> com.aol.cyclops.monad.AnyM<R> map(java.util.function.Function<? super T,? extends R> fn)
map in interface com.aol.cyclops.monad.AnyM<T>public final com.aol.cyclops.monad.AnyM<T> peek(java.util.function.Consumer<? super T> c)
peek in interface com.aol.cyclops.monad.AnyM<T>public final <R> com.aol.cyclops.monad.AnyM<R> bind(java.util.function.Function<? super T,?> fn)
bind in interface com.aol.cyclops.monad.AnyM<T>fn - flatMap functionpublic final <R> com.aol.cyclops.monad.AnyM<R> liftAndBind(java.util.function.Function<? super T,?> fn)
liftAndBind in interface com.aol.cyclops.monad.AnyM<T>fn - flatMap functionpublic final com.aol.cyclops.monad.AnyM<java.lang.Character> flatMapCharSequence(java.util.function.Function<? super T,java.lang.CharSequence> fn)
List<Character> result = anyM("input.file")
.liftAndBindCharSequence(i->"hello world")
.asSequence()
.toList();
assertThat(result,equalTo(Arrays.asList('h','e','l','l','o',' ','w','o','r','l','d')));
flatMapCharSequence in interface com.aol.cyclops.monad.FlatMapM<T>fn - public final com.aol.cyclops.monad.AnyM<java.lang.String> flatMapFile(java.util.function.Function<? super T,java.io.File> fn)
List<String> result = anyM("input.file")
.map(getClass().getClassLoader()::getResource)
.peek(System.out::println)
.map(URL::getFile)
.liftAndBindFile(File::new)
.asSequence()
.toList();
assertThat(result,equalTo(Arrays.asList("hello","world")));
flatMapFile in interface com.aol.cyclops.monad.FlatMapM<T>fn - public final com.aol.cyclops.monad.AnyM<java.lang.String> flatMapURL(java.util.function.Function<? super T,java.net.URL> fn)
List<String> result = anyM("input.file")
.liftAndBindURL(getClass().getClassLoader()::getResource)
.asSequence()
.toList();
assertThat(result,equalTo(Arrays.asList("hello","world")));
flatMapURL in interface com.aol.cyclops.monad.FlatMapM<T>fn - public final com.aol.cyclops.monad.AnyM<java.lang.String> flatMapBufferedReader(java.util.function.Function<? super T,java.io.BufferedReader> fn)
List<String> result = anyM("input.file")
.map(getClass().getClassLoader()::getResourceAsStream)
.map(InputStreamReader::new)
.liftAndBindBufferedReader(BufferedReader::new)
.asSequence()
.toList();
assertThat(result,equalTo(Arrays.asList("hello","world")));
flatMapBufferedReader in interface com.aol.cyclops.monad.FlatMapM<T>fn - public final <T1> com.aol.cyclops.monad.AnyM<T1> flatten()
flatten in interface com.aol.cyclops.monad.AnyM<T>public final com.aol.cyclops.monad.AnyM<java.util.List<T>> aggregate(com.aol.cyclops.monad.AnyM<T> next)
List<Integer> result = anyM(Stream.of(1,2,3,4))
.aggregate(anyM(Optional.of(5)))
.asSequence()
.toList();
assertThat(result,equalTo(Arrays.asList(1,2,3,4,5)));
aggregate in interface com.aol.cyclops.monad.AnyM<T>next - Monad to aggregate content withpublic final <R> com.aol.cyclops.monad.AnyM<java.util.List<R>> aggregateUntyped(com.aol.cyclops.monad.AnyM<?> next)
public void forEach(java.util.function.Consumer<? super T> action)
forEach in interface java.lang.Iterable<T>public final <R> com.aol.cyclops.monad.AnyM<R> flatMap(java.util.function.Function<? super T,com.aol.cyclops.monad.AnyM<? extends R>> fn)
flatMap in interface com.aol.cyclops.monad.AnyM<T>fn - public final <R> com.aol.cyclops.monad.AnyM<R> flatMapStream(java.util.function.Function<? super T,java.util.stream.BaseStream<? extends R,?>> fn)
flatMapStream in interface com.aol.cyclops.monad.FlatMapM<T>fn - public final <R> com.aol.cyclops.monad.AnyM<R> flatMapStreamable(java.util.function.Function<? super T,com.aol.cyclops.sequence.streamable.Streamable<R>> fn)
flatMapStreamable in interface com.aol.cyclops.monad.FlatMapM<T>fn - public final <R> com.aol.cyclops.monad.AnyM<R> flatMapCollection(java.util.function.Function<? super T,java.util.Collection<? extends R>> fn)
AnyM<Integer> opt = anyM(Optional.of(20));
Optional<List<Integer>> optionalList = opt.flatMap( i -> anyM(Stream.of(1,2,i))).unwrap();
//Optional [1,2,20]
In such cases using Arrays.asList would be more performant
AnyM<Integer> opt = anyM(Optional.of(20));
Optional<List<Integer>> optionalList = opt.flatMapCollection( i -> asList(1,2,i))).unwrap();
//Optional [1,2,20]
flatMapCollection in interface com.aol.cyclops.monad.FlatMapM<T>fn - public final <R> com.aol.cyclops.monad.AnyM<R> flatMapOptional(java.util.function.Function<? super T,java.util.Optional<? extends R>> fn)
flatMapOptional in interface com.aol.cyclops.monad.FlatMapM<T>fn - public final <R> com.aol.cyclops.monad.AnyM<R> flatMapCompletableFuture(java.util.function.Function<? super T,java.util.concurrent.CompletableFuture<? extends R>> fn)
flatMapCompletableFuture in interface com.aol.cyclops.monad.FlatMapM<T>public final <R> com.aol.cyclops.monad.AnyM<R> flatMapSequenceM(java.util.function.Function<? super T,com.aol.cyclops.sequence.SequenceM<? extends R>> fn)
flatMapSequenceM in interface com.aol.cyclops.monad.FlatMapM<T>public final <NT> com.aol.cyclops.sequence.SequenceM<NT> toSequence(java.util.function.Function<T,java.util.stream.Stream<NT>> fn)
Optional<List<Integer>> into Stream<Integer>
List<Integer> list = anyM(Optional.of(Arrays.asList(1,2,3,4,5,6)))
.<Integer>toSequence(c->c.stream())
.collect(Collectors.toList());
assertThat(list,hasItems(1,2,3,4,5,6));
toSequence in interface com.aol.cyclops.monad.AnyM<T>public final <T> com.aol.cyclops.sequence.SequenceM<T> toSequence()
Optional<List<Integer>> into Stream<Integer>
Less type safe equivalent, but may be more accessible than toSequence(fn) i.e.
toSequence(Function<T,Stream<NT>> fn)
List<Integer> list = anyM(Optional.of(Arrays.asList(1,2,3,4,5,6)))
.<Integer>toSequence()
.collect(Collectors.toList());
toSequence in interface com.aol.cyclops.monad.AnyM<T>public final com.aol.cyclops.sequence.SequenceM<T> asSequence()
Optional<List<Integer>> into Stream<List<Integer>>
If the underlying monad is a Stream it is returned
Otherwise we flatMap the underlying monad to a Stream typeasSequence in interface com.aol.cyclops.monad.AnyM<T>public final <R> com.aol.cyclops.monad.AnyM<R> applyM(com.aol.cyclops.monad.AnyM<java.util.function.Function<? super T,? extends R>> fn)
applyM in interface com.aol.cyclops.monad.AnyM<T>public <T> com.aol.cyclops.monad.AnyM<T> unit(T value)
unit in interface com.aol.cyclops.monad.AnyM<T>public <T> com.aol.cyclops.monad.AnyM<T> empty()
empty in interface com.aol.cyclops.monad.AnyM<T>public final com.aol.cyclops.monad.AnyM<java.util.List<T>> replicateM(int times)
replicateM in interface com.aol.cyclops.monad.AnyM<T>public final com.aol.cyclops.monad.AnyM<T> reduceMOptional(com.aol.cyclops.sequence.Monoid<java.util.Optional<T>> reducer)
reduceMOptional in interface com.aol.cyclops.monad.ReduceM<T>public final com.aol.cyclops.monad.AnyM<T> reduceMStream(com.aol.cyclops.sequence.Monoid<java.util.stream.Stream<T>> reducer)
reduceMStream in interface com.aol.cyclops.monad.ReduceM<T>public final com.aol.cyclops.monad.AnyM<T> reduceMStreamable(com.aol.cyclops.sequence.Monoid<com.aol.cyclops.sequence.streamable.Streamable<T>> reducer)
reduceMStreamable in interface com.aol.cyclops.monad.ReduceM<T>public final com.aol.cyclops.monad.AnyM<T> reduceMIterable(com.aol.cyclops.sequence.Monoid<java.lang.Iterable<T>> reducer)
reduceMIterable in interface com.aol.cyclops.monad.ReduceM<T>public final com.aol.cyclops.monad.AnyM<T> reduceMCompletableFuture(com.aol.cyclops.sequence.Monoid<java.util.concurrent.CompletableFuture<T>> reducer)
reduceMCompletableFuture in interface com.aol.cyclops.monad.ReduceM<T>public final com.aol.cyclops.monad.AnyM<T> reduceM(com.aol.cyclops.sequence.Monoid<com.aol.cyclops.monad.AnyM<T>> reducer)
reduceM in interface com.aol.cyclops.monad.AnyM<T>public com.aol.cyclops.sequence.SequenceM<T> stream()
public java.lang.String toString()
toString in interface com.aol.cyclops.monad.AnyM<T>toString in class java.lang.Objectpublic java.util.List<T> toList()
toList in interface com.aol.cyclops.monad.AnyM<T>public java.util.Set<T> toSet()
toSet in interface com.aol.cyclops.monad.AnyM<T>public java.util.Iterator<T> iterator()
public <R> com.aol.cyclops.monad.AnyM<R> applyMStream(java.util.stream.Stream<java.util.function.Function<? super T,? extends R>> fn)
applyMStream in interface com.aol.cyclops.monad.ApplyM<T>public <R> com.aol.cyclops.monad.AnyM<R> applyMOptional(java.util.Optional<java.util.function.Function<? super T,? extends R>> fn)
applyMOptional in interface com.aol.cyclops.monad.ApplyM<T>public <R> com.aol.cyclops.monad.AnyM<R> applyMCompletableFuture(java.util.concurrent.CompletableFuture<java.util.function.Function<? super T,? extends R>> fn)
applyMCompletableFuture in interface com.aol.cyclops.monad.ApplyM<T>public <R1,R> com.aol.cyclops.monad.AnyM<R> forEach2(java.util.function.Function<? super T,? extends com.aol.cyclops.monad.AnyM<R1>> monad, java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends R>> yieldingFunction)
forEach2 in interface com.aol.cyclops.monad.AnyM<T>public <R1,R> com.aol.cyclops.monad.AnyM<R> forEach2(java.util.function.Function<? super T,? extends com.aol.cyclops.monad.AnyM<R1>> monad, java.util.function.Function<? super T,java.util.function.Function<? super R1,java.lang.Boolean>> filterFunction, java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends R>> yieldingFunction)
forEach2 in interface com.aol.cyclops.monad.AnyM<T>public <R1,R2,R> com.aol.cyclops.monad.AnyM<R> forEach3(java.util.function.Function<? super T,? extends com.aol.cyclops.monad.AnyM<R1>> monad1, java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends com.aol.cyclops.monad.AnyM<R2>>> monad2, java.util.function.Function<? super T,java.util.function.Function<? super R1,java.util.function.Function<? super R2,? extends R>>> yieldingFunction)
forEach3 in interface com.aol.cyclops.monad.AnyM<T>public <R1,R2,R> com.aol.cyclops.monad.AnyM<R> forEach3(java.util.function.Function<? super T,? extends com.aol.cyclops.monad.AnyM<R1>> monad1, java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends com.aol.cyclops.monad.AnyM<R2>>> monad2, java.util.function.Function<? super T,java.util.function.Function<? super R1,java.util.function.Function<? super R2,java.lang.Boolean>>> filterFunction, java.util.function.Function<? super T,java.util.function.Function<? super R1,java.util.function.Function<? super R2,? extends R>>> yieldingFunction)
forEach3 in interface com.aol.cyclops.monad.AnyM<T>