A
- Type of data stored inside the nested CompletableFuturespublic interface CompletableFutureT<A> extends To<CompletableFutureT<A>>, Unit<A>, org.reactivestreams.Publisher<A>, Functor<A>, Foldable<A>, Filterable<A>, ToStream<A>
Modifier and Type | Method and Description |
---|---|
default <B> CompletableFutureT<B> |
bind(java.util.function.Function<? super A,CompletableFutureT<? extends B>> f) |
default <U> CompletableFutureT<U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
<R> CompletableFutureT<R> |
empty() |
static <T> CompletableFutureTSeq<T> |
emptyList() |
static <T> CompletableFutureTValue<T> |
emptyMaybe() |
MaybeT<A> |
filter(java.util.function.Predicate<? super A> test)
Keep only elements for which the supplied predicates hold
e.g.
|
default MaybeT<A> |
filterNot(java.util.function.Predicate<? super A> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
<B> CompletableFutureT<B> |
flatMap(java.util.function.Function<? super A,? extends MonadicValue<? extends B>> f) |
static <A> CompletableFutureT<A> |
fromAnyM(AnyM<A> anyM) |
static <A> CompletableFutureTSeq<A> |
fromAnyMSeq(AnyMSeq<A> anyM) |
static <A> CompletableFutureTValue<A> |
fromAnyMValue(AnyMValue<A> anyM) |
static <A> CompletableFutureTValue<A> |
fromFuture(java.util.concurrent.CompletableFuture<java.util.concurrent.CompletableFuture<A>> future) |
static <A> CompletableFutureTSeq<A> |
fromIterable(java.lang.Iterable<java.util.concurrent.CompletableFuture<A>> iterableOfCompletableFutures) |
static <A> CompletableFutureTValue<A> |
fromIterableValue(java.lang.Iterable<java.util.concurrent.CompletableFuture<A>> iterableOfCompletableFutures) |
static <A> CompletableFutureTValue<A> |
fromOptional(java.util.Optional<java.util.concurrent.CompletableFuture<A>> optional) |
static <A> CompletableFutureTSeq<A> |
fromPublisher(org.reactivestreams.Publisher<java.util.concurrent.CompletableFuture<A>> publisherOfCompletableFutures) |
static <A> CompletableFutureTSeq<A> |
fromStream(java.util.stream.Stream<java.util.concurrent.CompletableFuture<A>> streamOfCompletableFutures) |
static <A,V extends MonadicValue<java.util.concurrent.CompletableFuture<A>>> |
fromValue(V monadicValue) |
static <U,R> java.util.function.Function<CompletableFutureT<U>,CompletableFutureT<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<CompletableFutureT<U1>,CompletableFutureT<U2>,CompletableFutureT<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> CompletableFutureT<B> |
map(java.util.function.Function<? super A,? extends B> f)
Map the wrapped CompletableFuture
|
default MaybeT<A> |
notNull()
Filter elements retaining only values which are not null
|
static <A> CompletableFutureT<A> |
of(AnyM<java.util.concurrent.CompletableFuture<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> CompletableFutureT<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
|
CompletableFutureT<A> |
peek(java.util.function.Consumer<? super A> peek)
Peek at the current value of the CompletableFuture
|
default ReactiveSeq<A> |
stream() |
default <R> CompletableFutureT<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
|
AnyM<java.util.concurrent.CompletableFuture<A>> |
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> CompletableFutureT<R> empty()
MaybeT<A> filter(java.util.function.Predicate<? super A> test)
Filterable
of(1,2,3).filter(i->i>2);
//[3]
filter
in interface Filterable<A>
test
- to filter elements by, retaining matchesdefault <B> CompletableFutureT<B> bind(java.util.function.Function<? super A,CompletableFutureT<? extends B>> f)
static <A> CompletableFutureT<A> of(AnyM<java.util.concurrent.CompletableFuture<A>> monads)
monads
- AnyM that contains a monad wrapping an MaybeCompletableFutureT<A> peek(java.util.function.Consumer<? super A> peek)
CompletableFutureT.of(AnyM.fromStream(Arrays.asCompletableFuture(10))
.peek(System.out::println);
//prints 10
<B> CompletableFutureT<B> map(java.util.function.Function<? super A,? extends B> f)
CompletableFutureT.of(AnyM.fromStream(Arrays.asCompletableFuture(10))
.map(t->t=t+1);
//CompletableFutureT<AnyM<Stream<CompletableFuture[11]>>>
<B> CompletableFutureT<B> flatMap(java.util.function.Function<? super A,? extends MonadicValue<? extends B>> f)
static <U,R> java.util.function.Function<CompletableFutureT<U>,CompletableFutureT<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);
AnyM<Integer> stream = AnyM.fromStream(withNulls);
AnyM<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]);
fn
- Function to enhance with functionality from CompletableFuture and another monad typestatic <U1,U2,R> java.util.function.BiFunction<CompletableFutureT<U1>,CompletableFutureT<U2>,CompletableFutureT<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);
AnyM<Integer> stream = AnyM.ofMonad(withNulls);
AnyM<CompletableFuture<Integer>> streamOpt = stream.map(CompletableFuture::completedFuture);
CompletableFuture<CompletableFuture<Integer>> two = CompletableFuture.completedFuture(CompletableFuture.completedFuture(2));
AnyM<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]);
fn
- BiFunction to enhance with functionality from CompletableFuture and another monad typestatic <A> CompletableFutureT<A> fromAnyM(AnyM<A> anyM)
static <A> CompletableFutureTValue<A> fromAnyMValue(AnyMValue<A> anyM)
static <A> CompletableFutureTSeq<A> fromAnyMSeq(AnyMSeq<A> anyM)
static <A> CompletableFutureTSeq<A> fromIterable(java.lang.Iterable<java.util.concurrent.CompletableFuture<A>> iterableOfCompletableFutures)
static <A> CompletableFutureTSeq<A> fromStream(java.util.stream.Stream<java.util.concurrent.CompletableFuture<A>> streamOfCompletableFutures)
static <A> CompletableFutureTSeq<A> fromPublisher(org.reactivestreams.Publisher<java.util.concurrent.CompletableFuture<A>> publisherOfCompletableFutures)
static <A,V extends MonadicValue<java.util.concurrent.CompletableFuture<A>>> CompletableFutureTValue<A> fromValue(V monadicValue)
static <A> CompletableFutureTValue<A> fromOptional(java.util.Optional<java.util.concurrent.CompletableFuture<A>> optional)
static <A> CompletableFutureTValue<A> fromFuture(java.util.concurrent.CompletableFuture<java.util.concurrent.CompletableFuture<A>> future)
static <A> CompletableFutureTValue<A> fromIterableValue(java.lang.Iterable<java.util.concurrent.CompletableFuture<A>> iterableOfCompletableFutures)
static <T> CompletableFutureTValue<T> emptyMaybe()
static <T> CompletableFutureTSeq<T> emptyList()
default <U> CompletableFutureT<U> cast(java.lang.Class<? extends U> type)
Functor
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)default <R> CompletableFutureT<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 Functor<A>
mapper
- TCO Transformation functiondefault <R> CompletableFutureT<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 Functor<A>
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<A>
default MaybeT<A> filterNot(java.util.function.Predicate<? super A> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[1,2]
filterNot
in interface Filterable<A>
fn
- to filter elements by, retaining matchesdefault MaybeT<A> notNull()
Filterable
of(1,2,null,4).nonNull();
//[1,2,4]
notNull
in interface Filterable<A>
default ReactiveSeq<A> stream()