T
- public class CompletableFutureT<A>
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
<B> CompletableFutureT<B> |
flatMap(java.util.function.Function<? super A,CompletableFutureT<B>> f)
Flat Map the wrapped CompletableFuture
|
static <A> CompletableFutureT<A> |
fromAnyM(AnyM<A> anyM)
|
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
|
static <A> CompletableFutureT<A> |
of(AnyM<java.util.concurrent.CompletableFuture<A>> monads)
Construct an CompletableFutureT from an AnyM that wraps a monad containing CompletableFutures
|
CompletableFutureT<A> |
peek(java.util.function.Consumer<? super A> peek)
Peek at the current value of the CompletableFuture
|
java.lang.String |
toString() |
AnyM<java.util.concurrent.CompletableFuture<A>> |
unwrap() |
public CompletableFutureT<A> peek(java.util.function.Consumer<? super A> peek)
CompletableFutureT.of(AnyM.fromStream(Arrays.asCompletableFuture(10))
.peek(System.out::println);
//prints 10
peek
- Consumer to accept current value of CompletableFuturepublic <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]>>>
f
- Mapping function for the wrapped CompletableFuturepublic <B> CompletableFutureT<B> flatMap(java.util.function.Function<? super A,CompletableFutureT<B>> f)
CompletableFutureT.of(AnyM.fromStream(Arrays.asCompletableFuture(10))
.flatMap(t->CompletableFuture.completedFuture(20));
//CompletableFutureT<AnyM<Stream<CompletableFuture[20]>>>
f
- FlatMap functionpublic 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 typepublic 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)
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 typepublic static <A> CompletableFutureT<A> fromAnyM(AnyM<A> anyM)
anyM
- AnyM that doesn't contain a monad wrapping an CompletableFuturepublic static <A> CompletableFutureT<A> of(AnyM<java.util.concurrent.CompletableFuture<A>> monads)
monads
- AnyM that contains a monad wrapping an CompletableFuturepublic java.lang.String toString()
toString
in class java.lang.Object