T
- The type contained on the nested Eval(s) withinpublic interface EvalT<T> extends To<EvalT<T>>, org.reactivestreams.Publisher<T>, Functor<T>, Filterable<T>, Foldable<T>, ToStream<T>
Modifier and Type | Method and Description |
---|---|
default <B> EvalT<B> |
bind(java.util.function.Function<? super T,EvalT<? extends B>> f)
Flat Map the wrapped Maybe
|
default <U> EvalT<U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
<R> EvalT<R> |
empty() |
static <T> EvalTSeq<T> |
emptyList() |
static <T> EvalTValue<T> |
emptyMaybe() |
MaybeT<T> |
filter(java.util.function.Predicate<? super T> test)
Filter the wrapped Maybe
|
default MaybeT<T> |
filterNot(java.util.function.Predicate<? super T> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<B> EvalT<B> |
flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends B>> f) |
static <A> EvalT<A> |
fromAnyM(AnyM<A> anyM)
|
static <A> EvalTSeq<A> |
fromAnyMSeq(AnyMSeq<A> anyM) |
static <A> EvalTValue<A> |
fromAnyMValue(AnyMValue<A> anyM) |
static <A> EvalTValue<A> |
fromFuture(java.util.concurrent.CompletableFuture<Eval<A>> future) |
static <A> EvalTSeq<A> |
fromIterable(java.lang.Iterable<Eval<A>> iterableOfEvals) |
static <A> EvalTValue<A> |
fromIterableValue(java.lang.Iterable<Eval<A>> iterableOfEvals) |
static <A> EvalTValue<A> |
fromOptional(java.util.Optional<Eval<A>> optional) |
static <A> EvalTSeq<A> |
fromPublisher(org.reactivestreams.Publisher<Eval<A>> publisherOfEvals) |
static <A> EvalTSeq<A> |
fromStream(java.util.stream.Stream<Eval<A>> streamOfEvals) |
static <A,V extends MonadicValue<Eval<A>>> |
fromValue(V monadicValue) |
static <U,R> java.util.function.Function<EvalT<U>,EvalT<R>> |
lift(java.util.function.Function<? super U,? extends R> fn)
Lift a function into one that accepts and returns an MaybeT This allows
multiple monad types to add functionality to existing functions and
methods
e.g.
|
static <U1,U2,R> java.util.function.BiFunction<EvalT<U1>,EvalT<U2>,EvalT<R>> |
lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
Lift a BiFunction into one that accepts and returns MaybeTs This allows
multiple monad types to add functionality to existing functions and
methods
e.g.
|
<B> EvalT<B> |
map(java.util.function.Function<? super T,? extends B> f)
Map the wrapped Maybe
|
default MaybeT<T> |
notNull()
Filter elements retaining only values which are not null
|
static <A> EvalT<A> |
of(AnyM<Eval<A>> monads)
Construct an MaybeT from an AnyM that wraps a monad containing Maybes
|
default <U> MaybeT<U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
default <R> EvalT<R> |
patternMatch(java.util.function.Function<Matchable.CheckValue1<T,R>,Matchable.CheckValue1<T,R>> case1,
java.util.function.Supplier<? extends R> otherwise)
Transform the elements of this Stream with a Pattern Matching case and default value
|
EvalT<T> |
peek(java.util.function.Consumer<? super T> peek)
Peek at the current value of the Maybe
|
default ReactiveSeq<T> |
stream() |
default <R> EvalT<R> |
trampoline(java.util.function.Function<? super T,? extends Trampoline<? extends R>> mapper)
Performs a map operation that can call a recursive method without running out of stack space
|
<R> EvalT<R> |
unit(R value) |
AnyM<Eval<T>> |
unwrap() |
endsWith, endsWithIterable, findAny, findFirst, firstValue, foldable, foldRight, foldRight, foldRight, foldRightMapToType, get, groupBy, join, join, join, mapReduce, mapReduce, print, print, printErr, printOut, reduce, reduce, reduce, reduce, reduce, reduce, reduce, schedule, scheduleFixedDelay, scheduleFixedRate, single, single, singleOptional, startsWith, startsWithIterable, toConcurrentLazyCollection, toConcurrentLazyStreamable, toLazyCollection, validate, xMatch
futureStream, getStreamable, isEmpty, iterator, jdkStream, reactiveSeq, reveresedJDKStream, reveresedStream
<R> EvalT<R> unit(R value)
<R> EvalT<R> empty()
EvalT<T> peek(java.util.function.Consumer<? super T> peek)
MaybeT.of(AnyM.fromStream(Maybe.of(10))
.peek(System.out::println);
//prints 10
MaybeT<T> filter(java.util.function.Predicate<? super T> test)
MaybeT.of(AnyM.fromStream(Maybe.of(10))
.filter(t->t!=10);
//MaybeT<AnyM<Stream<Maybe.empty>>>
filter
in interface Filterable<T>
test
- Predicate to filter the wrapped Maybe<B> EvalT<B> map(java.util.function.Function<? super T,? extends B> f)
MaybeT.of(AnyM.fromStream(Maybe.of(10))
.map(t->t=t+1);
//MaybeT<AnyM<Stream<Maybe[11]>>>
default <B> EvalT<B> bind(java.util.function.Function<? super T,EvalT<? extends B>> f)
MaybeT.of(AnyM.fromStream(Maybe.of(10))
.bind(t->Maybe.empty();
//MaybeT<AnyM<Stream<Maybe.empty>>>
f
- FlatMap function<B> EvalT<B> flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends B>> f)
static <U,R> java.util.function.Function<EvalT<U>,EvalT<R>> lift(java.util.function.Function<? super U,? extends R> fn)
Function<Integer, Integer> add2 = i -> i + 2;
Function<MaybeT<Integer>, MaybeT<Integer>> optTAdd2 = MaybeT.lift(add2);
Stream<Integer> withNulls = Stream.of(1, 2, null);
AnyM<Integer> stream = AnyM.ofMonad(withNulls);
AnyM<Maybe<Integer>> streamOpt = stream.map(Maybe::ofNullable);
List<Integer> results = optTAdd2.apply(MaybeT.of(streamOpt)).unwrap().<Stream<Maybe<Integer>>> unwrap()
.filter(Maybe::isPresent).map(Maybe::get).collect(Collectors.toList());
// Arrays.asList(3,4);
fn
- Function to enhance with functionality from Maybe and another
monad typestatic <U1,U2,R> java.util.function.BiFunction<EvalT<U1>,EvalT<U2>,EvalT<R>> lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
fn
- BiFunction to enhance with functionality from Maybe and
another monad typestatic <A> EvalT<A> fromAnyM(AnyM<A> anyM)
anyM
- AnyM that doesn't contain a monad wrapping an Maybestatic <A> EvalT<A> of(AnyM<Eval<A>> monads)
monads
- AnyM that contains a monad wrapping an Maybestatic <A> EvalTValue<A> fromAnyMValue(AnyMValue<A> anyM)
static <A> EvalTSeq<A> fromPublisher(org.reactivestreams.Publisher<Eval<A>> publisherOfEvals)
static <A,V extends MonadicValue<Eval<A>>> EvalTValue<A> fromValue(V monadicValue)
static <A> EvalTValue<A> fromOptional(java.util.Optional<Eval<A>> optional)
static <A> EvalTValue<A> fromFuture(java.util.concurrent.CompletableFuture<Eval<A>> future)
static <A> EvalTValue<A> fromIterableValue(java.lang.Iterable<Eval<A>> iterableOfEvals)
static <T> EvalTValue<T> emptyMaybe()
static <T> EvalTSeq<T> emptyList()
default <U> EvalT<U> cast(java.lang.Class<? extends U> type)
Functor
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)default <R> EvalT<R> trampoline(java.util.function.Function<? super T,? extends Trampoline<? extends R>> mapper)
Functor
ReactiveSeq.of(10,20,30,40)
.trampoline(i-> fibonacci(i))
.forEach(System.out::println);
Trampoline<Long> fibonacci(int i){
return fibonacci(i,1,0);
}
Trampoline<Long> fibonacci(int n, long a, long b) {
return n == 0 ? Trampoline.done(b) : Trampoline.more( ()->fibonacci(n-1, a+b, a));
}
55
6765
832040
102334155
ReactiveSeq.of(10_000,200_000,3_000_000,40_000_000)
.trampoline(i-> fibonacci(i))
.forEach(System.out::println);
completes successfully
trampoline
in interface Functor<T>
mapper
- TCO Transformation functiondefault <R> EvalT<R> patternMatch(java.util.function.Function<Matchable.CheckValue1<T,R>,Matchable.CheckValue1<T,R>> case1, java.util.function.Supplier<? extends R> otherwise)
Functor
List<String> result = CollectionX.of(1,2,3,4)
.patternMatch(
c->c.valuesWhere(i->"even", (Integer i)->i%2==0 )
)
// CollectionX["odd","even","odd","even"]
patternMatch
in interface Functor<T>
case1
- Function to generate a case (or chain of cases as a single case)otherwise
- Value if supplied case doesn't matchdefault <U> MaybeT<U> ofType(java.lang.Class<? extends U> type)
Filterable
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
ofType
in interface Filterable<T>
default MaybeT<T> filterNot(java.util.function.Predicate<? super T> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[1,2]
filterNot
in interface Filterable<T>
fn
- to filter elements by, retaining matchesdefault MaybeT<T> notNull()
Filterable
of(1,2,null,4).nonNull();
//[1,2,4]
notNull
in interface Filterable<T>
default ReactiveSeq<T> stream()