T
- public class BaseAnyMImpl<T> extends java.lang.Object implements AnyM<T>
AnyM.AnyMFactory
FlatMap.Apply2<T1,T2>, FlatMap.Apply2Impl<T1,T2>, FlatMap.Apply3<T1,T2,T3>, FlatMap.Apply3Impl<T1,T2,T3>
ToStream.FromStreamable<T>
Constructor and Description |
---|
BaseAnyMImpl() |
Modifier and Type | Method and Description |
---|---|
AnyM<java.util.List<T>> |
aggregate(AnyM<T> next)
Aggregate the contents of this Monad and the supplied Monad
|
<R> AnyM<java.util.List<R>> |
aggregateUntyped(AnyM<?> next) |
<R> AnyM<R> |
applyM(AnyM<java.util.function.Function<? super T,? extends R>> fn) |
ReactiveSeq<T> |
asSequence()
Wrap this Monad's contents as a Sequence without disaggreating it.
|
<R> 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> AnyM<T> |
empty()
Construct an AnyM wrapping an empty instance of the wrapped type
e.g.
|
<T> AnyM<T> |
emptyUnit() |
AnyM<T> |
filter(java.util.function.Predicate<? super T> fn)
Perform a filter operation on the wrapped monad instance e.g.
|
<R> AnyM<R> |
flatMap(java.util.function.Function<? super T,? extends AnyM<? extends R>> fn)
flatMap operation
|
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
|
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.
|
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.
|
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> AnyM<T1> |
flatten()
join / flatten one level of a nested hierarchy
|
void |
forEach(java.util.function.Consumer<? super T> action) |
<R1,R> AnyM<R> |
forEach2(java.util.function.Function<? super T,? extends AnyM<R1>> monad,
java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends R>> yieldingFunction) |
<R1,R> AnyM<R> |
forEach2(java.util.function.Function<? super T,? extends 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> AnyM<R> |
forEach3(java.util.function.Function<? super T,? extends AnyM<R1>> monad1,
java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends 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> AnyM<R> |
forEach3(java.util.function.Function<? super T,? extends AnyM<R1>> monad1,
java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends 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) |
T |
get() |
java.util.Iterator<T> |
iterator() |
<R> 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> AnyM<R> |
map(java.util.function.Function<? super T,? extends R> fn)
Perform a map operation on the wrapped monad instance e.g.
|
Monad |
monad() |
AnyM<T> |
peek(java.util.function.Consumer<? super T> c)
Perform a peek operation on the wrapped monad e.g.
|
AnyM<T> |
reduceM(Monoid<AnyM<T>> reducer)
Perform a reduction where NT is a (native) Monad type
e.g.
|
AnyMValue<T> |
reduceMCompletableFuture(Monoid<java.util.concurrent.CompletableFuture<T>> reducer)
Perform a reduction where NT is a (native) Monad type
e.g.
|
AnyMValue<T> |
reduceMEval(Monoid<Eval<T>> reducer) |
AnyMSeq<T> |
reduceMIterable(Monoid<java.lang.Iterable<T>> reducer)
Perform a reduction where NT is a (native) Monad type
e.g.
|
AnyMValue<T> |
reduceMMaybe(Monoid<Maybe<T>> reducer) |
AnyMValue<T> |
reduceMOptional(Monoid<java.util.Optional<T>> reducer)
Perform a reduction where NT is a (native) Monad type
e.g.
|
AnyMSeq<T> |
reduceMStream(Monoid<java.util.stream.Stream<T>> reducer)
Perform a reduction where NT is a (native) Monad type
e.g.
|
AnyMSeq<T> |
reduceMStreamable(Monoid<Streamable<T>> reducer)
Perform a reduction where NT is a (native) Monad type
e.g.
|
AnyMValue<T> |
reduceMXor(Monoid<Xor<?,T>> reducer) |
AnyM<java.util.List<T>> |
replicateM(int times)
Replicate given Monad
|
ReactiveSeq<T> |
stream() |
java.util.List<T> |
toList() |
<T> ReactiveSeq<T> |
toSequence()
Optional<List<Integer>> into Stream<Integer> |
<NT> ReactiveSeq<NT> |
toSequence(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends NT>> fn)
Sequence the contents of a Monad.
|
java.util.Set<T> |
toSet() |
java.lang.String |
toString() |
<T> AnyM<T> |
unit(T value)
Construct a new instanceof AnyM using the type of the underlying wrapped monad
|
<U> AnyM<U> |
unitIterator(java.util.Iterator<U> it) |
<R> R |
unwrap() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
fromArray, fromCollection, fromCompletableFuture, fromDoubleStream, fromEval, fromFile, fromFutureW, fromIntStream, fromIor, fromIterable, fromList, fromLongStream, fromMaybe, fromOptional, fromOptionalDouble, fromOptionalInt, fromOptionalLong, fromRange, fromRangeLong, fromSet, fromStream, fromStreamable, fromURL, fromXor, liftM, liftM2, liftM2, liftM3, liftM3, liftM3Cyclops, liftM4, liftM4, liftM4Cyclops, liftM5, liftM5, liftM5Cyclops, listFromCollection, listFromCompletableFuture, listFromEval, listFromFutureW, listFromIor, listFromIterable, listFromIterator, listFromMaybe, listFromOptional, listFromStream, listFromStreamable, listFromXor, ofConvertable, ofMonad, ofMonadList, ofNullable, ofSeq, ofValue, sequence, sequence, streamOf, traverse, traverse
foldRight, foldRight, foldRightMapToType, join, join, join, mapReduce, mapReduce, print, print, printErr, printOut, reduce, reduce, reduce, reduce, reduce, reduce
cast, patternMatch, trampoline
getStreamable, isEmpty, reactiveSeq, reveresedSequenceM, reveresedStream
public final <R> R unwrap()
unwrap
in interface AnyM<T>
unwrap
in interface Unwrapable
public final <R,A> R collect(java.util.stream.Collector<? super T,A,R> collector)
public final AnyM<T> filter(java.util.function.Predicate<? super T> fn)
AnyM
AnyM.fromOptional(Optional.of(10)).filter(i->i<10);
//AnyM[Optional.empty()]
AnyM.fromStream(Stream.of(5,10)).filter(i->i<10);
//AnyM[Stream[5]]
public final <R> AnyM<R> map(java.util.function.Function<? super T,? extends R> fn)
AnyM
AnyM.fromIterable(Try.runWithCatch(this::loadData))
.map(data->transform(data))
AnyM.fromStream(Stream.of(1,2,3))
.map(i->i+2);
AnyM[Stream[3,4,5]]
public final AnyM<T> peek(java.util.function.Consumer<? super T> c)
AnyM
AnyM.fromCompletableFuture(CompletableFuture.supplyAsync(()->loadData())
.peek(System.out::println)
public final <R> AnyM<R> bind(java.util.function.Function<? super T,?> fn)
public final <R> AnyM<R> liftAndBind(java.util.function.Function<? super T,?> fn)
liftAndBind
in interface AnyM<T>
fn
- flatMap functionpublic final 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')));
fn
- public final 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")));
fn
- public final 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")));
fn
- public final 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")));
fn
- public final <T1> AnyM<T1> flatten()
public final AnyM<java.util.List<T>> aggregate(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)));
public void forEach(java.util.function.Consumer<? super T> action)
forEach
in interface java.lang.Iterable<T>
public final <R> AnyM<R> flatMap(java.util.function.Function<? super T,? extends AnyM<? extends R>> fn)
fn
- public final <NT> ReactiveSeq<NT> toSequence(java.util.function.Function<? super T,? extends java.util.stream.Stream<? extends 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 AnyM<T>
public final <T> ReactiveSeq<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 AnyM<T>
public final ReactiveSeq<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 AnyM<T>
public <T> AnyM<T> unit(T value)
AnyM
AnyM<Integer> ints = AnyM.fromList(Arrays.asList(1,2,3);
AnyM<String> string = ints.unit("hello");
public <T> AnyM<T> empty()
AnyM
Any<Integer> ints = AnyM.fromStream(Stream.of(1,2,3));
AnyM<Integer> empty=ints.empty();
public final AnyM<java.util.List<T>> replicateM(int times)
AnyM
AnyM<Optional<Integer>> applied =AnyM.fromOptional(Optional.of(2)).replicateM(5);
//AnyM[Optional[List(2,2,2,2,2)]]
replicateM
in interface AnyM<T>
times
- number of times to replicatepublic final AnyMValue<T> reduceMOptional(Monoid<java.util.Optional<T>> reducer)
ReduceM
Monoid<Optional<Integer>> optionalAdd = Monoid.of(Optional.of(0), (a,b)-> Optional.of(a.get()+b.get()));
AnyM.fromStream(Stream.of(2,8,3,1)).reduceM(optionalAdd);
//AnyM[Optional(14)];
reduceMOptional
in interface ReduceM<T>
reducer
- An identity value (approx. a seed) and BiFunction with a single type to reduce this anyMpublic final AnyMValue<T> reduceMMaybe(Monoid<Maybe<T>> reducer)
reduceMMaybe
in interface ReduceM<T>
public final AnyMValue<T> reduceMXor(Monoid<Xor<?,T>> reducer)
reduceMXor
in interface ReduceM<T>
public final AnyMValue<T> reduceMEval(Monoid<Eval<T>> reducer)
reduceMEval
in interface ReduceM<T>
public final AnyMSeq<T> reduceMStream(Monoid<java.util.stream.Stream<T>> reducer)
ReduceM
Monoid<Optional<Integer>> streamableAdd = Monoid.of(Stream.of(0), (a,b)-> Stream.of(a.get()+b.get()));
AnyM.fromStream(Stream.of(2,8,3,1)).reduceM(streamableAdd);
//AnyM[Optional(14)];
reduceMStream
in interface ReduceM<T>
reducer
- An identity value (approx. a seed) and BiFunction with a single type to reduce this anyMpublic final AnyMSeq<T> reduceMStreamable(Monoid<Streamable<T>> reducer)
ReduceM
Monoid<Optional<Integer>> streamableAdd = Monoid.of(Streamable.of(0), (a,b)-> Streamable.of(a.get()+b.get()));
AnyM.fromStream(Stream.of(2,8,3,1)).reduceM(streamableAdd);
//AnyM[Optional(14)];
reduceMStreamable
in interface ReduceM<T>
reducer
- An identity value (approx. a seed) and BiFunction with a single type to reduce this anyMpublic final AnyMSeq<T> reduceMIterable(Monoid<java.lang.Iterable<T>> reducer)
ReduceM
Monoid<Optional<Integer>> streamableAdd = Monoid.of(Streamable.of(0), (a,b)-> Streamable.of(a.get()+b.get()));
AnyM.fromStream(Stream.of(2,8,3,1)).reduceM(streamableAdd);
//AnyM[Optional(14)];
reduceMIterable
in interface ReduceM<T>
reducer
- An identity value (approx. a seed) and BiFunction with a single type to reduce this anyMpublic final AnyMValue<T> reduceMCompletableFuture(Monoid<java.util.concurrent.CompletableFuture<T>> reducer)
ReduceM
Monoid<Optional<Integer>> streamableAdd = Monoid.of(CompletableFuture.completedFuture(0), (a,b)-> CompletableFuture.supplyAsync(()->a.get()+b.get()));
AnyM.fromStream(Stream.of(2,8,3,1)).reduceM(streamableAdd);
//AnyM[Optional(14)];
reduceMCompletableFuture
in interface ReduceM<T>
reducer
- An identity value (approx. a seed) and BiFunction with a single type to reduce this anyMpublic final AnyM<T> reduceM(Monoid<AnyM<T>> reducer)
AnyM
Monoid<Optional<Integer>> optionalAdd = Monoid.of(AnyM.fromOptional(Optional.of(0)), (a,b)-> AnyM.fromOptional(Optional.of(a.get()+b.get())));
AnyM.fromStream(Stream.of(2,8,3,1)).reduceM(optionalAdd);
//AnyM[Optional(14)];
public ReactiveSeq<T> stream()
public java.lang.String toString()
public java.util.List<T> toList()
public java.util.Set<T> toSet()
public java.util.Iterator<T> iterator()
public <R1,R> AnyM<R> forEach2(java.util.function.Function<? super T,? extends AnyM<R1>> monad, java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends R>> yieldingFunction)
public <R1,R> AnyM<R> forEach2(java.util.function.Function<? super T,? extends 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)
public <R1,R2,R> AnyM<R> forEach3(java.util.function.Function<? super T,? extends AnyM<R1>> monad1, java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends AnyM<R2>>> monad2, java.util.function.Function<? super T,java.util.function.Function<? super R1,java.util.function.Function<? super R2,? extends R>>> yieldingFunction)
public <R1,R2,R> AnyM<R> forEach3(java.util.function.Function<? super T,? extends AnyM<R1>> monad1, java.util.function.Function<? super T,java.util.function.Function<? super R1,? extends 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)
public <U> AnyM<U> unitIterator(java.util.Iterator<U> it)
public T get()