T
- public class CompletableFutureTValue<A> extends java.lang.Object implements CompletableFutureT<A>, TransformerValue<A>, MonadicValue<A>, java.util.function.Supplier<A>, ConvertableFunctor<A>, Filterable<A>, ApplicativeFunctor<A>, Matchable.ValueAndOptionalMatcher<A>
ApplicativeFunctor.Applicatives, ApplicativeFunctor.ApplyFunctions<T>
Value.ValueImpl<T>
Convertable.SupplierToConvertable<T>
Modifier and Type | Method and Description |
---|---|
<T2,R> CompletableFutureTValue<R> |
ap(Value<? extends T2> app,
java.util.function.BiFunction<? super A,? super T2,? extends R> fn) |
<U> CompletableFutureTValue<U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
<R> CompletableFutureTValue<R> |
empty() |
static <T> CompletableFutureTValue<T> |
emptyOptional() |
boolean |
equals(java.lang.Object o) |
MaybeTValue<A> |
filter(java.util.function.Predicate<? super A> test)
Filter the wrapped Maybe
|
MaybeTValue<A> |
filterNot(java.util.function.Predicate<? super A> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<B> CompletableFutureTValue<B> |
flatMap(java.util.function.Function<? super A,? extends MonadicValue<? extends B>> f) |
<B> CompletableFutureTValue<B> |
flatMapT(java.util.function.Function<? super A,CompletableFutureTValue<B>> f)
Flat Map the wrapped CompletableFuture
|
static <A> CompletableFutureTValue<A> |
fromAnyM(AnyMValue<A> anyM)
|
static <A,V extends MonadicValue<java.util.concurrent.CompletableFuture<A>>> |
fromValue(V monadicValue) |
A |
get() |
int |
hashCode() |
boolean |
isFuturePresent() |
boolean |
isValuePresent() |
java.util.Iterator<A> |
iterator() |
static <U,R> java.util.function.Function<CompletableFutureTValue<U>,CompletableFutureTValue<R>> |
lift(java.util.function.Function<? super U,? extends R> fn)
Lift a function into one that accepts and returns an CompletableFutureT
This allows multiple monad types to add functionality to existing functions and methods
e.g.
|
static <U1,U2,R> java.util.function.BiFunction<CompletableFutureTValue<U1>,CompletableFutureTValue<U2>,CompletableFutureTValue<R>> |
lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
Lift a BiFunction into one that accepts and returns CompletableFutureTs
This allows multiple monad types to add functionality to existing functions and methods
e.g.
|
<B> CompletableFutureTValue<B> |
map(java.util.function.Function<? super A,? extends B> f)
Map the wrapped CompletableFuture
|
MaybeTValue<A> |
notNull()
Filter elements retaining only values which are not null
|
static <A> CompletableFutureTValue<A> |
of(AnyMValue<java.util.concurrent.CompletableFuture<A>> monads)
Construct an CompletableFutureT from an AnyM that wraps a monad containing CompletableFutures
|
static <A> CompletableFutureTValue<A> |
of(java.util.concurrent.CompletableFuture<A> maybe) |
<U> MaybeTValue<U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
<R> CompletableFutureTValue<R> |
patternMatch(java.util.function.Function<Matchable.CheckValue1<A,R>,Matchable.CheckValue1<A,R>> case1,
java.util.function.Supplier<? extends R> otherwise)
Transform the elements of this Stream with a Pattern Matching case and default value
|
CompletableFutureTValue<A> |
peek(java.util.function.Consumer<? super A> peek)
Peek at the current value of the CompletableFuture
|
ReactiveSeq<A> |
stream() |
void |
subscribe(org.reactivestreams.Subscriber<? super A> s) |
boolean |
test(A t) |
java.lang.String |
toString() |
<R> CompletableFutureTValue<R> |
trampoline(java.util.function.Function<? super A,? extends Trampoline<? extends R>> mapper)
Performs a map operation that can call a recursive method without running out of stack space
|
<R> CompletableFutureTValue<R> |
unit(R value) |
AnyMValue<java.util.concurrent.CompletableFuture<A>> |
unwrap() |
FutureW<A> |
value() |
<T2,R> CompletableFutureTValue<R> |
zip(java.util.function.BiFunction<? super A,? super T2,? extends R> fn,
org.reactivestreams.Publisher<? extends T2> app) |
<T2,R> CompletableFutureTValue<R> |
zip(java.lang.Iterable<? extends T2> app,
java.util.function.BiFunction<? super A,? super T2,? extends R> fn) |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
bind, emptyList, emptyMaybe, fromAnyM, fromAnyMSeq, fromAnyMValue, fromFuture, fromIterable, fromIterableValue, fromOptional, fromPublisher, fromStream, of
futureStream, getStreamable, isEmpty, jdkStream, reactiveSeq, reveresedJDKStream, reveresedStream
isPresent
anyM, coflatMap, nest
applyFunctions
collect, fold, fold, generate, iterate, mapReduce, mkString, newSubscriber, of, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFeatureToggle, toFutureStream, toFutureStream, toIor, toLazyImmutable, toList, toListX, toMaybe, toMutable, toPBagX, toPOrderedSetX, toPQueueX, toPSetX, toPStackX, toPVectorX, toQueueX, toSetX, toSimpleReact, toSimpleReact, toSortedSetX, toTry, toTry, toTry, toXor, toXor, unapply
endsWith, endsWithIterable, findAny, findFirst, firstValue, foldable, foldRight, foldRight, foldRight, foldRightMapToType, get, groupBy, join, join, join, 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
collect, fromSupplier, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toFutureWAsync, toFutureWAsync, toOptional, toOptionalAtomicReference, toStream, visit
toOptional, visit
matches
public AnyMValue<java.util.concurrent.CompletableFuture<A>> unwrap()
unwrap
in interface CompletableFutureT<A>
public FutureW<A> value()
value
in interface TransformerValue<A>
public boolean isValuePresent()
isValuePresent
in interface TransformerValue<A>
public MaybeTValue<A> filter(java.util.function.Predicate<? super A> test)
MaybeT.of(AnyM.fromStream(Maybe.of(10))
.filter(t->t!=10);
//MaybeT<AnyMValue<Stream<Maybe.empty>>>
filter
in interface CompletableFutureT<A>
filter
in interface TransformerValue<A>
filter
in interface Filterable<A>
test
- Predicate to filter the wrapped Maybepublic CompletableFutureTValue<A> peek(java.util.function.Consumer<? super A> peek)
CompletableFutureT.of(AnyM.fromStream(Arrays.asCompletableFuture(10))
.peek(System.out::println);
//prints 10
peek
in interface CompletableFutureT<A>
peek
in interface TransformerValue<A>
peek
in interface Functor<A>
peek
- Consumer to accept current value of CompletableFuturepublic <B> CompletableFutureTValue<B> map(java.util.function.Function<? super A,? extends B> f)
CompletableFutureT.of(AnyM.fromStream(Arrays.asCompletableFuture(10))
.map(t->t=t+1);
//CompletableFutureT<AnyMValue<Stream<CompletableFuture[11]>>>
map
in interface CompletableFutureT<A>
map
in interface TransformerValue<A>
map
in interface ConvertableFunctor<A>
map
in interface Functor<A>
map
in interface MonadicValue<A>
f
- Mapping function for the wrapped CompletableFuturepublic <T2,R> CompletableFutureTValue<R> ap(Value<? extends T2> app, java.util.function.BiFunction<? super A,? super T2,? extends R> fn)
ap
in interface ApplicativeFunctor<A>
public <T2,R> CompletableFutureTValue<R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super A,? super T2,? extends R> fn)
zip
in interface ApplicativeFunctor<A>
public <T2,R> CompletableFutureTValue<R> zip(java.util.function.BiFunction<? super A,? super T2,? extends R> fn, org.reactivestreams.Publisher<? extends T2> app)
zip
in interface ApplicativeFunctor<A>
public <B> CompletableFutureTValue<B> flatMapT(java.util.function.Function<? super A,CompletableFutureTValue<B>> f)
CompletableFutureT.of(AnyM.fromStream(Arrays.asCompletableFuture(10))
.flatMap(t->CompletableFuture.completedFuture(20));
//CompletableFutureT<AnyMValue<Stream<CompletableFuture[20]>>>
f
- FlatMap functionpublic <B> CompletableFutureTValue<B> flatMap(java.util.function.Function<? super A,? extends MonadicValue<? extends B>> f)
flatMap
in interface CompletableFutureT<A>
public static <U,R> java.util.function.Function<CompletableFutureTValue<U>,CompletableFutureTValue<R>> lift(java.util.function.Function<? super U,? extends R> fn)
Function<Integer,Integer> add2 = i -> i+2;
Function<CompletableFutureT<Integer>, CompletableFutureT<Integer>> optTAdd2 = CompletableFutureT.lift(add2);
Stream<Integer> withNulls = Stream.of(1,2,3);
AnyMValue<Integer> stream = AnyM.fromStream(withNulls);
AnyMValue<CompletableFuture<Integer>> streamOpt = stream.map(CompletableFuture::completedFuture);
List<Integer> results = optTAdd2.apply(CompletableFutureT.of(streamOpt))
.unwrap()
.<Stream<CompletableFuture<Integer>>>unwrap()
.map(CompletableFuture::join)
.collect(Collectors.toList());
//CompletableFuture.completedFuture(List[3,4]);
lift
in interface CompletableFutureT<A>
fn
- Function to enhance with functionality from CompletableFuture and another monad typepublic static <U1,U2,R> java.util.function.BiFunction<CompletableFutureTValue<U1>,CompletableFutureTValue<U2>,CompletableFutureTValue<R>> lift2(java.util.function.BiFunction<? super U1,? super U2,? extends R> fn)
BiFunction<Integer,Integer,Integer> add = (a,b) -> a+b;
BiFunction<CompletableFutureT<Integer>,CompletableFutureT<Integer>,CompletableFutureT<Integer>> optTAdd2 = CompletableFutureT.lift2(add);
Stream<Integer> withNulls = Stream.of(1,2,3);
AnyMValue<Integer> stream = AnyM.ofMonad(withNulls);
AnyMValue<CompletableFuture<Integer>> streamOpt = stream.map(CompletableFuture::completedFuture);
CompletableFuture<CompletableFuture<Integer>> two = CompletableFuture.completedFuture(CompletableFuture.completedFuture(2));
AnyMValue<CompletableFuture<Integer>> future= AnyM.fromCompletableFuture(two);
List<Integer> results = optTAdd2.apply(CompletableFutureT.of(streamOpt),CompletableFutureT.of(future))
.unwrap()
.<Stream<CompletableFuture<Integer>>>unwrap()
.map(CompletableFuture::join)
.collect(Collectors.toList());
//CompletableFuture.completedFuture(List[3,4,5]);
lift2
in interface CompletableFutureT<A>
fn
- BiFunction to enhance with functionality from CompletableFuture and another monad typepublic static <A> CompletableFutureTValue<A> fromAnyM(AnyMValue<A> anyM)
anyM
- AnyM that doesn't contain a monad wrapping an CompletableFuturepublic static <A> CompletableFutureTValue<A> of(AnyMValue<java.util.concurrent.CompletableFuture<A>> monads)
monads
- AnyM that contains a monad wrapping an CompletableFuturepublic static <A> CompletableFutureTValue<A> of(java.util.concurrent.CompletableFuture<A> maybe)
public static <A,V extends MonadicValue<java.util.concurrent.CompletableFuture<A>>> CompletableFutureTValue<A> fromValue(V monadicValue)
fromValue
in interface CompletableFutureT<A>
public java.lang.String toString()
toString
in class java.lang.Object
public A get()
get
in interface Convertable<A>
get
in interface java.util.function.Supplier<A>
public ReactiveSeq<A> stream()
public java.util.Iterator<A> iterator()
iterator
in interface Matchable.MatchableOptional<A>
iterator
in interface Matchable.ValueAndOptionalMatcher<A>
iterator
in interface Convertable<A>
iterator
in interface ToStream<A>
iterator
in interface java.lang.Iterable<A>
public void subscribe(org.reactivestreams.Subscriber<? super A> s)
public boolean isFuturePresent()
public boolean test(A t)
public <R> CompletableFutureTValue<R> unit(R value)
unit
in interface TransformerValue<A>
unit
in interface MonadicValue<A>
unit
in interface Unit<A>
public <R> CompletableFutureTValue<R> empty()
empty
in interface CompletableFutureT<A>
public static <T> CompletableFutureTValue<T> emptyOptional()
public <U> CompletableFutureTValue<U> cast(java.lang.Class<? extends U> type)
Functor
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)cast
in interface CompletableFutureT<A>
cast
in interface TransformerValue<A>
cast
in interface Functor<A>
public <R> CompletableFutureTValue<R> trampoline(java.util.function.Function<? super A,? 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 CompletableFutureT<A>
trampoline
in interface TransformerValue<A>
trampoline
in interface Functor<A>
public <R> CompletableFutureTValue<R> patternMatch(java.util.function.Function<Matchable.CheckValue1<A,R>,Matchable.CheckValue1<A,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 CompletableFutureT<A>
patternMatch
in interface TransformerValue<A>
patternMatch
in interface Functor<A>
case1
- Function to generate a case (or chain of cases as a single case)otherwise
- Value if supplied case doesn't matchpublic <U> MaybeTValue<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 CompletableFutureT<A>
ofType
in interface Filterable<A>
public MaybeTValue<A> filterNot(java.util.function.Predicate<? super A> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[1,2]
filterNot
in interface CompletableFutureT<A>
filterNot
in interface Filterable<A>
fn
- to filter elements by, retaining matchespublic MaybeTValue<A> notNull()
Filterable
of(1,2,null,4).nonNull();
//[1,2,4]
notNull
in interface CompletableFutureT<A>
notNull
in interface Filterable<A>
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object