T
- Type of wrapped future valuepublic class Future<T> extends java.lang.Object implements To<Future<T>>, MonadicValue<T>, Completable<T>, Higher<DataWitness.future,T>, RecoverableFrom<java.lang.Throwable,T>, Zippable<T>, ReactiveTransformable<T>, OrElseValue<T,Future<T>>
Constructor and Description |
---|
Future() |
Modifier and Type | Method and Description |
---|---|
static <T,R> Future<R> |
accumulate(java.lang.Iterable<Future<T>> fts,
java.util.function.Function<? super T,R> mapper,
Monoid<R> reducer)
Asynchronously accumulate the results of a batch of Futures which using the supplied mapping function to
convert the data from each Future before reducing them using the supplied supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two
input values of the same type and returns the combined result)
cyclops2.Monoids . |
static <T,R> Future<R> |
accumulate(java.lang.Iterable<Future<T>> fts,
Reducer<R,T> reducer)
Asynchronously accumulate the results of Futures, a single failure will cause a failed result, using the supplied Reducer
cyclops2.Reducers |
static <T> Future<T> |
accumulate(Monoid<T> reducer,
java.lang.Iterable<Future<T>> fts)
Asynchronously accumulate the results only from the provided Futures,
reducing them using the supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two
input values of the same type and returns the combined result)
cyclops2.Monoids
A single Failure results in a Failed Future. |
static <T,R> Future<R> |
accumulateSuccess(java.lang.Iterable<Future<T>> fts,
java.util.function.Function<? super T,R> mapper,
Monoid<R> reducer)
Asynchronously accumulate the results only from those Futures which have completed successfully, using the supplied mapping function to
convert the data from each Future before reducing them using the supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two
input values of the same type and returns the combined result)
cyclops2.Monoids . |
static <T,R> Future<R> |
accumulateSuccess(java.lang.Iterable<Future<T>> fts,
Reducer<R,T> reducer)
Asynchronously accumulate the results only from those Futures which have completed successfully.
|
static <T> Future<T> |
accumulateSuccess(Monoid<T> reducer,
java.lang.Iterable<Future<T>> fts)
Asynchronously accumulate the results only from those Futures which have completed successfully,
reducing them using the supplied Monoid (a combining BiFunction/BinaryOperator and identity element that takes two
input values of the same type and returns the combined result)
cyclops2.Monoids . |
static <T> Future<T> |
allOf(Future<T>... fts)
Wait until all the provided Future's to complete
|
static <T> Future<T> |
anyOf(Future<T>... fts)
Select the first Future to complete
|
static <T> Future<T> |
async(java.util.concurrent.Executor ex,
java.util.function.Supplier<T> s) |
void |
cancel()
If not already completed, completes this Future with a
CancellationException
Passes true to @see java.util.concurrent.CompletableFuture#cancel as mayInterruptIfRunning parameter on that method
has no effect for the default CompletableFuture implementation |
boolean |
complete(T value)
If not already completed, sets the value of this Future to the provided value
|
boolean |
completeExceptionally(java.lang.Throwable e)
Complete this Future with an Exception
|
<R> Future<R> |
concatMap(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> mapper)
A flattening transformation operation that takes the first value from the returned Iterable.
|
static <T> Future<T> |
empty()
An zero Future
|
<T1> Future<T1> |
emptyUnit() |
Maybe<T> |
filter(java.util.function.Predicate<? super T> fn)
Keep only elements for which the supplied predicates hold
e.g.
|
Maybe<T> |
filterNot(java.util.function.Predicate<? super T> fn)
Remove any elements for which the predicate holds (inverse operation to filter)
e.g.
|
static <T> Future<T> |
firstSuccess(Future<T>... fts)
Select the first Future to return with a successful result
|
<R> Future<R> |
flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> mapper)
A flattening transformation operation (@see
Optional.flatMap(Function) |
<R> Future<R> |
flatMapCf(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<? extends R>> mapper)
A flatMap operation that accepts a CompleteableFuture CompletionStage as
the return type
|
static <R> Future<R> |
flatten(Future<? extends Future<R>> nested) |
<R> R |
fold(java.util.function.Function<? super T,? extends R> success,
java.util.function.Function<? super java.lang.Throwable,? extends R> failure)
Blocking analogue to visitAsync.
|
<R> R |
fold(java.util.function.Function<? super T,? extends R> success,
java.util.function.Supplier<? extends R> failure) |
<R> Future<R> |
foldAsync(java.util.function.Function<? super T,? extends R> success,
java.util.function.Function<? super java.lang.Throwable,? extends R> failure) |
void |
forEach(java.util.function.Consumer<? super T> c) |
void |
forEach(java.util.function.Consumer<? super T> onNext,
java.util.function.Consumer<java.lang.Throwable> onError) |
void |
forEach(java.util.function.Consumer<? super T> onNext,
java.util.function.Consumer<java.lang.Throwable> onError,
java.lang.Runnable onComplete) |
<R1,R> Future<R> |
forEach2(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends R> yieldingFunction)
Perform a two level nested internal iteration over this MonadicValue and the
supplied MonadicValue
|
<R1,R> Future<R> |
forEach2(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,java.lang.Boolean> filterFunction,
java.util.function.BiFunction<? super T,? super R1,? extends R> yieldingFunction)
Perform a two level nested internal iteration over this MonadicValue and the
supplied stream
|
<T2,R1,R2,R> |
forEach3(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2,
Function3<? super T,? super R1,? super R2,? extends R> yieldingFunction)
Perform a three level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
<T2,R1,R2,R> |
forEach3(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2,
Function3<? super T,? super R1,? super R2,java.lang.Boolean> filterFunction,
Function3<? super T,? super R1,? super R2,? extends R> yieldingFunction)
Perform a three level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
<T2,R1,R2,R3,R> |
forEach4(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2,
Function3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3,
Function4<? super T,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
Perform a four level nested internal iteration over this MonadicValue and the
supplied MonadicValues
|
<T2,R1,R2,R3,R> |
forEach4(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1,
java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2,
Function3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3,
Function4<? super T,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction,
Function4<? super T,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
Perform a four level nested internal iteration over this MonadicValue and the
supplied MonadicValues
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c<100,
(a,b,c,d)->a+b+c+d);
//Maybe.none
|
static <T> Future<T> |
fromIterable(java.lang.Iterable<T> iterable)
Construct a Future syncrhonously that contains a single value extracted from the supplied Iterable
|
static <T> Future<T> |
fromIterable(java.lang.Iterable<T> iterable,
java.util.concurrent.Executor ex)
Construct a Future asyncrhonously that contains a single value extracted from the supplied Iterable
|
static <T> Future<T> |
fromPublisher(org.reactivestreams.Publisher<? extends T> pub)
Construct a Future syncrhonously that contains a single value extracted from the supplied reactive-streams Publisher
|
static <T> Future<T> |
fromPublisher(org.reactivestreams.Publisher<T> pub,
java.util.concurrent.Executor ex)
Construct a Future asynchronously that contains a single value extracted from the supplied reactive-streams Publisher
|
static <T,X extends java.lang.Throwable> |
fromTry(Try<T,X> value)
Construct a Future syncrhonously from the Supplied Try
|
static <T> Future<T> |
future()
An zero Future
|
Try<T,java.lang.Throwable> |
get() |
java.util.concurrent.CompletableFuture<T> |
getFuture() |
T |
getOrElse(T alt) |
boolean |
isCancelled() |
boolean |
isDone() |
boolean |
isFailed() |
boolean |
isPresent() |
boolean |
isSuccess() |
<R> Future<R> |
map(java.util.function.Function<? super T,? extends R> fn)
Transform this functor using the supplied transformation function
|
<R> Future<R> |
map(java.util.function.Function<? super T,? extends R> fn,
java.util.concurrent.Executor ex)
Asyncrhonous transform operation
|
<R> Future<R> |
map(java.util.function.Function<? super T,R> success,
java.util.function.Function<java.lang.Throwable,R> failure)
Map this Future differently depending on whether the previous stage
completed successfully or failed
|
<R> Future<R> |
mergeMap(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> mapper)
A flattening transformation operation that takes the first value from the returned Publisher.
|
java.lang.String |
mkString()
Returns the class name and the name of the subclass, if there is any value, the value is showed between square brackets.
|
static <T> Future<T> |
narrow(Future<? extends T> of) |
static <T> Future<T> |
narrowK(Higher<DataWitness.future,T> future)
Convert the raw Higher Kinded Type for FutureType types into the FutureType type definition class
|
Maybe<T> |
notNull()
Filter elements retaining only values which are not null
|
static <T> Future<T> |
of(java.util.concurrent.CompletableFuture<T> f)
Create a Future instance from the supplied CompletableFuture
|
static <T> Future<T> |
of(java.util.function.Supplier<T> s)
Create a Future object that asyncrhonously populates using the Common
ForkJoinPool from the user provided Supplier
|
static <T> Future<T> |
of(java.util.function.Supplier<T> s,
java.util.concurrent.Executor ex)
Create a Future object that asyncrhonously populates using the provided
Executor and Supplier
|
static <T> Future<T> |
ofError(java.lang.Throwable error)
Construct a completed-with-error Future from the given Exception
|
static <T> Future<T> |
ofResult(T result)
Construct a successfully completed Future from the given value
|
<U> Maybe<U> |
ofType(java.lang.Class<? extends U> type)
Keep only those elements in a stream that are of a given type.
|
Future<T> |
peek(java.util.function.Consumer<? super T> c)
Peek at the current value of this Transformable, without transforming it
|
Future<T> |
recover(java.util.function.Function<? super java.lang.Throwable,? extends T> fn)
Returns a new Future that, when this Future completes exceptionally is
executed with this Future exception as the argument to the supplied
function.
|
Future<T> |
recover(java.util.function.Supplier<? extends T> fn) |
static <T> Future<T> |
schedule(long delay,
java.util.concurrent.ScheduledExecutorService ex,
java.util.function.Supplier<T> t)
Schedule the population of a Future from the provided Supplier after the specified delay.
|
static <T> Future<T> |
schedule(java.lang.String cron,
java.util.concurrent.ScheduledExecutorService ex,
java.util.function.Supplier<T> t)
Schedule the population of a Future from the provided Supplier, the provided Cron (Quartz format) expression will be used to
trigger the population of the Future.
|
static <T> Future<ReactiveSeq<T>> |
sequence(java.lang.Iterable<? extends Future<T>> fts)
Asynchronous sequence operation that convert a Collection of Futures to a Future with a List
|
static <T> Future<ReactiveSeq<T>> |
sequence(ReactiveSeq<? extends Future<T>> stream) |
static <T> Future<ReactiveSeq<T>> |
sequence(java.util.stream.Stream<? extends Future<T>> fts)
Sequence operation that convert a Stream of Futures to a Future with a Stream
|
ReactiveSeq<T> |
stream() |
void |
subscribe(org.reactivestreams.Subscriber<? super T> sub) |
static <T,R> Future<R> |
tailRec(T initial,
java.util.function.Function<? super T,? extends Future<? extends Either<T,R>>> fn) |
java.util.concurrent.CompletableFuture<T> |
toCompletableFuture() |
Either<java.lang.Throwable,T> |
toEither() |
Ior<java.lang.Throwable,T> |
toIor() |
Maybe<T> |
toMaybe() |
java.lang.String |
toString() |
static <T,R> Future<ReactiveSeq<R>> |
traverse(java.util.function.Function<? super T,? extends R> fn,
ReactiveSeq<Future<T>> stream) |
<T> Future<T> |
unit(T unit) |
<R> Future<R> |
visitAsync(java.util.function.Function<? super T,? extends R> success,
java.util.function.Function<? super java.lang.Throwable,? extends R> failure)
Deprecated.
|
static <T> Higher<DataWitness.future,T> |
widen(Future<T> narrow) |
<T2,R> Future<R> |
zip(java.util.function.BiFunction<? super T,? super T2,? extends R> fn,
org.reactivestreams.Publisher<? extends T2> app)
Zip (combine) this Zippable with the supplied Publisher, using the supplied combining function
|
<T2,R> Future<R> |
zip(java.lang.Iterable<? extends T2> app,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Iterable using the supplied combining function
|
<U> Future<Tuple2<T,U>> |
zip(java.lang.Iterable<? extends U> other) |
<S,U> Future<Tuple3<T,S,U>> |
zip3(java.lang.Iterable<? extends S> second,
java.lang.Iterable<? extends U> third) |
<S,U,R> Future<R> |
zip3(java.lang.Iterable<? extends S> second,
java.lang.Iterable<? extends U> third,
Function3<? super T,? super S,? super U,? extends R> fn3) |
<T2,T3,T4> Future<Tuple4<T,T2,T3,T4>> |
zip4(java.lang.Iterable<? extends T2> second,
java.lang.Iterable<? extends T3> third,
java.lang.Iterable<? extends T4> fourth) |
<T2,T3,T4,R> |
zip4(java.lang.Iterable<? extends T2> second,
java.lang.Iterable<? extends T3> third,
java.lang.Iterable<? extends T4> fourth,
Function4<? super T,? super T2,? super T3,? super T4,? extends R> fn) |
<U> Future<Tuple2<T,U>> |
zipWithPublisher(org.reactivestreams.Publisher<? extends U> other) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
arity, attemptMap, mapAsync, mapRetry, mapRetry, mapTry, mapTry
retry, retry
orElseUse, orElseUse
asSupplier, collect, fold, generate, iterate, iterator, nonEmptyList, nonEmptyListGet, orElse, orElseGet, print, print, printErr, printOut, toEither, toLazyEither, toLeft, toOption, toOptional, toRight, toTry, toTry, toTry
public static <T,R> Future<R> tailRec(T initial, java.util.function.Function<? super T,? extends Future<? extends Either<T,R>>> fn)
public static <T> Higher<DataWitness.future,T> widen(Future<T> narrow)
public final void subscribe(org.reactivestreams.Subscriber<? super T> sub)
public static <T> Future<T> narrowK(Higher<DataWitness.future,T> future)
future
- HKT encoded list into a FutureTypepublic static <T> Future<T> empty()
public static <T> Future<T> future()
public static <T> Future<T> anyOf(Future<T>... fts)
fts
- Futures to raceCompletableFuture.anyOf(CompletableFuture...)
public static <T> Future<T> allOf(Future<T>... fts)
fts
- Futures to wait onCompletableFuture.allOf(CompletableFuture...)
@SafeVarargs public static <T> Future<T> firstSuccess(Future<T>... fts)
Future<Integer> ft = Future.future();
Future<Integer> result = Future.firstSuccess(Future.of(()->1),ft);
ft.complete(10);
result.getValue() //1
fts
- Futures to racepublic boolean completeExceptionally(java.lang.Throwable e)
completeExceptionally
in interface Completable<T>
e
- Throwable to complete this Future withCompletableFuture.completeExceptionally(Throwable)
public static <T> Future<T> fromPublisher(org.reactivestreams.Publisher<T> pub, java.util.concurrent.Executor ex)
ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
Future<Integer> future = Future.fromPublisher(stream,ex);
//Future[1]
pub
- Publisher to extract value fromex
- Executor to extract value onpublic static <T> Future<T> fromIterable(java.lang.Iterable<T> iterable, java.util.concurrent.Executor ex)
ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
Future<Integer> future = Future.fromIterable(stream,ex);
//Future[1]
iterable
- Iterable to generate a Future fromex
- Executor to extract value onpublic static <T> Future<T> fromPublisher(org.reactivestreams.Publisher<? extends T> pub)
ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
Future<Integer> future = Future.fromPublisher(stream);
//Future[1]
pub
- Publisher to extract value frompublic static <T> Future<T> fromIterable(java.lang.Iterable<T> iterable)
ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
Future<Integer> future = Future.fromIterable(stream);
//Future[1]
iterable
- Iterable to extract value frompublic static <T> Future<T> of(java.util.concurrent.CompletableFuture<T> f)
f
- CompletableFuture to wrap as a Futurepublic void forEach(java.util.function.Consumer<? super T> c)
public void forEach(java.util.function.Consumer<? super T> onNext, java.util.function.Consumer<java.lang.Throwable> onError)
public void forEach(java.util.function.Consumer<? super T> onNext, java.util.function.Consumer<java.lang.Throwable> onError, java.lang.Runnable onComplete)
public static <T,X extends java.lang.Throwable> Future<T> fromTry(Try<T,X> value)
value
- Try to populate Future frompublic static <T> Future<T> schedule(java.lang.String cron, java.util.concurrent.ScheduledExecutorService ex, java.util.function.Supplier<T> t)
Future<String> future = Future.schedule("* * * * * ?", Executors.newScheduledThreadPool(1), ()->"hello");
//Future["hello"]
cron
- Cron expression in Quartz formatex
- ScheduledExecutorService used to execute the provided Suppliert
- The Supplier to execute to populate the Futurepublic static <T> Future<T> schedule(long delay, java.util.concurrent.ScheduledExecutorService ex, java.util.function.Supplier<T> t)
Future<String> future = Future.schedule(10l, Executors.newScheduledThreadPool(1), ()->"hello");
//Future["hello"]
delay
- Delay after which the Future should be populatedex
- ScheduledExecutorService used to execute the provided Suppliert
- he Supplier to execute to populate the Futurepublic static <T> Future<ReactiveSeq<T>> sequence(java.lang.Iterable<? extends Future<T>> fts)
Future<Seq<Integer>> futures =Future.sequence(Seq.of(Future.ofResult(10),Future.ofResult(1)));
//Seq.of(10,1)
fts
- Collection of Futures to Sequence into a Future with a Listpublic static <T> Future<ReactiveSeq<T>> sequence(java.util.stream.Stream<? extends Future<T>> fts)
Future<Integer> just = Future.ofResult(10);
Future<ReactiveSeq<Integer>> futures =Future.sequence(Stream.of(just,Future.ofResult(1)));
//Seq.of(10,1)
fts
- Strean of Futures to Sequence into a Future with a Streampublic static <T> Future<ReactiveSeq<T>> sequence(ReactiveSeq<? extends Future<T>> stream)
public static <T,R> Future<ReactiveSeq<R>> traverse(java.util.function.Function<? super T,? extends R> fn, ReactiveSeq<Future<T>> stream)
public static <T,R> Future<R> accumulateSuccess(java.lang.Iterable<Future<T>> fts, Reducer<R,T> reducer)
accumulate(Iterable, Reducer)
if you would like a failure to result in a Future
with an error
Future<Integer> just =Future.of(CompletableFuture.completedFuture(10));
Future<Integer> none = Future.ofError(new NoSuchElementException());
Future<PersistentSetX<Integer>> futures = Future.accumulateSuccess(Seq.of(just,none,Future.ofResult(1)),Reducers.toPersistentSetX());
//Future[PersistentSetX[10,1]]
fts
- Collection of Futures to accumulate successesreducer
- Reducer to accumulate resultspublic static <T,R> Future<R> accumulate(java.lang.Iterable<Future<T>> fts, Reducer<R,T> reducer)
cyclops2.Reducers
Future<Integer> just =Future.of(CompletableFuture.completedFuture(10));
Future<Integer> none = Future.ofError(new NoSuchElementException());
Future<PersistentSetX<Integer>> futures = Future.accumulateSuccess(Seq.of(just,none,Future.ofResult(1)),Reducers.toPersistentSetX());
//Future[PersistentSetX[10,1]]
fts
- Collection of Futures to accumulate successesreducer
- Reducer to accumulate resultspublic static <T,R> Future<R> accumulateSuccess(java.lang.Iterable<Future<T>> fts, java.util.function.Function<? super T,R> mapper, Monoid<R> reducer)
cyclops2.Monoids
.
Future<String> future = Future.accumulate(Seq.of(Future.ofResult(10),Future.ofResult(1)),i->""+i,Monoids.stringConcat);
//Future["101"]
fts
- Collection of Futures to accumulate successesmapper
- Mapping function to be applied to the result of each Futurereducer
- Monoid to combine values from each Futurepublic static <T> Future<T> accumulateSuccess(Monoid<T> reducer, java.lang.Iterable<Future<T>> fts)
cyclops2.Monoids
.
Future<Integer> just =Future.of(CompletableFuture.completedFuture(10));
Future<Integer> future =Future.accumulate(Monoids.intSum, Seq.of(just,Future.ofResult(1)));
//Future[11]
fts
- Collection of Futures to accumulate successesreducer
- Monoid to combine values from each Futurepublic static <T,R> Future<R> accumulate(java.lang.Iterable<Future<T>> fts, java.util.function.Function<? super T,R> mapper, Monoid<R> reducer)
cyclops2.Monoids
.
A single Failure results in a Failed Future.
Future<String> future = Future.accumulate(Seq.of(Future.ofResult(10),Future.ofResult(1)),i->""+i,Monoids.stringConcat);
//Future["101"]
fts
- Collection of Futures to accumulate successesmapper
- Mapping function to be applied to the result of each Futurereducer
- Monoid to combine values from each Futurepublic static <T> Future<T> accumulate(Monoid<T> reducer, java.lang.Iterable<Future<T>> fts)
cyclops2.Monoids
A single Failure results in a Failed Future.
Future<Integer> future =Future.accumulate(Monoids.intSum,Seq.of(just,Future.ofResult(1)));
//Future[11]
fts
- Collection of Futures to accumulate successesreducer
- Monoid to combine values from each Futurepublic <T2,R1,R2,R3,R> Future<R> forEach4(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2, Function3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3, Function4<? super T,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c+d);
//Maybe.none
forEach4
in interface MonadicValue<T>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overvalue3
- Nested MonadicValue to iterate overyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementspublic <T2,R1,R2,R3,R> Future<R> forEach4(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2, Function3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3, Function4<? super T,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction, Function4<? super T,? super R1,? super R2,? super R3,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach4(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->Maybe.none(),
(a,b,c,d)->a+b+c<100,
(a,b,c,d)->a+b+c+d);
//Maybe.none
forEach4
in interface MonadicValue<T>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overvalue3
- Nested MonadicValue to iterate overfilterFunction
- Filter to applyHKT over elements before passing non-filtered
values to the yielding functionyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementspublic <T2,R1,R2,R> Future<R> forEach3(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2, Function3<? super T,? super R1,? super R2,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach3(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->a+b+c<100,
(a,b,c)->a+b+c);
//Maybe[32]
forEach3
in interface MonadicValue<T>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementspublic <T2,R1,R2,R> Future<R> forEach3(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends MonadicValue<R2>> value2, Function3<? super T,? super R1,? super R2,java.lang.Boolean> filterFunction, Function3<? super T,? super R1,? super R2,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach3(a->Maybe.just(a+10),
(a,b)->Maybe.just(a+b),
(a,b,c)->a+b+c<100,
(a,b,c)->a+b+c);
//Maybe[32]
forEach3
in interface MonadicValue<T>
value1
- Nested MonadicValue to iterate overvalue2
- Nested MonadicValue to iterate overfilterFunction
- Filter to applyHKT over elements before passing non-filtered
values to the yielding functionyieldingFunction
- Function with pointers to the current element from both
MonadicValue that generates the new elementspublic <R1,R> Future<R> forEach2(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach2(a->Maybe.none(),
(a,b)->a+b);
//Maybe.none()
forEach2
in interface MonadicValue<T>
value1
- Nested Monadic Type to iterate overyieldingFunction
- Function with pointers to the current element from both
monad types that generates the new elementspublic <R1,R> Future<R> forEach2(java.util.function.Function<? super T,? extends MonadicValue<R1>> value1, java.util.function.BiFunction<? super T,? super R1,java.lang.Boolean> filterFunction, java.util.function.BiFunction<? super T,? super R1,? extends R> yieldingFunction)
MonadicValue
Maybe.of(3)
.forEach2(a->Maybe.none(),
a->b-> a<3 && b>10,
(a,b)->a+b);
//Maybe.none()
forEach2
in interface MonadicValue<T>
value1
- Nested monadic type to iterate overfilterFunction
- Filter to applyHKT over elements before passing non-filtered
values to the yielding functionyieldingFunction
- Function with pointers to the current element from both
Streams that generates the new elements@Deprecated public <R> Future<R> visitAsync(java.util.function.Function<? super T,? extends R> success, java.util.function.Function<? super java.lang.Throwable,? extends R> failure)
Future.ofResult(10)
.visitAsync(i->i*2, e->-1);
//Future[20]
Future.<Integer>ofError(new RuntimeException())
.visitAsync(i->i*2, e->-1)
//Future[-1]
success
- Function to execute if the previous stage completes successfullyfailure
- Function to execute if this Future failspublic <R> Future<R> foldAsync(java.util.function.Function<? super T,? extends R> success, java.util.function.Function<? super java.lang.Throwable,? extends R> failure)
public <R> R fold(java.util.function.Function<? super T,? extends R> success, java.util.function.Function<? super java.lang.Throwable,? extends R> failure)
Future.ofResult(10)
.visit(i->i*2, e->-1);
//20
Future.<Integer>ofError(new RuntimeException())
.visit(i->i*2, e->-1)
//[-1]
success
- Function to execute if the previous stage completes successfullyfailure
- Function to execute if this Future failspublic <R> Future<R> map(java.util.function.Function<? super T,? extends R> fn)
Transformable
of(1,2,3).map(i->i*2)
//[2,4,6]
map
in interface Transformable<T>
map
in interface MonadicValue<T>
fn
- Transformation functionpublic <R> Future<R> map(java.util.function.Function<? super T,? extends R> fn, java.util.concurrent.Executor ex)
fn
- Transformation functionex
- Executor to execute the transformation asynchronouslyCompletableFuture.thenApplyAsync(Function, Executor)
public boolean isSuccess()
public boolean isDone()
isDone
in interface Completable<T>
CompletableFuture.isDone()
public boolean isCancelled()
CompletableFuture.isCancelled()
public void cancel()
CancellationException
Passes true to @see java.util.concurrent.CompletableFuture#cancel as mayInterruptIfRunning parameter on that method
has no effect for the default CompletableFuture implementationpublic boolean complete(T value)
complete
in interface Completable<T>
value
- Value to set this Future topublic boolean isFailed()
isFailed
in interface Completable<T>
public <T> Future<T> unit(T unit)
public <T1> Future<T1> emptyUnit()
public ReactiveSeq<T> stream()
public <R> Future<R> flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> mapper)
MonadicValue
Optional.flatMap(Function)
Eval.now(1).map(i->i+2).flatMap(i->Eval.later(()->i*3);
//Eval[9]
flatMap
in interface MonadicValue<T>
mapper
- transformation functionpublic <R> Future<R> flatMapCf(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<? extends R>> mapper)
mapper
- Mapping functionpublic java.util.concurrent.CompletableFuture<T> toCompletableFuture()
public Future<T> recover(java.util.function.Function<? super java.lang.Throwable,? extends T> fn)
Future.ofError(new RuntimeException())
.recover(__ -> true)
//Future[true]
recover
in interface RecoverableFrom<java.lang.Throwable,T>
fn
- the function to use to compute the value of the returned
Future if this Future completed exceptionallypublic Future<T> recover(java.util.function.Supplier<? extends T> fn)
recover
in interface Recoverable<T>
public <R> Future<R> map(java.util.function.Function<? super T,R> success, java.util.function.Function<java.lang.Throwable,R> failure)
Future.ofResult(1)
.map(i->i*2,e->-1);
//Future[2]
success
- Mapping function for successful outcomesfailure
- Mapping function for failed outcomespublic Future<T> peek(java.util.function.Consumer<? super T> c)
Transformable
of(1,2,3).map(System.out::println)
1
2
3
peek
in interface Transformable<T>
c
- Consumer that recieves each element from this Transformablepublic java.lang.String toString()
toString
in class java.lang.Object
public static <T> Future<T> ofResult(T result)
result
- To wrap inside a Futurepublic static <T> Future<T> ofError(java.lang.Throwable error)
error
- To wrap inside a Futurepublic java.lang.String mkString()
Value
public Maybe<T> filter(java.util.function.Predicate<? super T> fn)
Filters
of(1,2,3).filter(i->i>2);
//[3]
public <U> Maybe<U> ofType(java.lang.Class<? extends U> type)
Filters
// (1, 2, 3) ReactiveSeq.of(1, "a", 2, "b",3).ofType(Integer.class)
public Maybe<T> filterNot(java.util.function.Predicate<? super T> fn)
Filters
of(1,2,3).filter(i->i>2);
//[1,2]
public Maybe<T> notNull()
Filters
of(1,2,null,4).nonNull();
//[1,2,4]
public <U> Future<Tuple2<T,U>> zipWithPublisher(org.reactivestreams.Publisher<? extends U> other)
zipWithPublisher
in interface Zippable<T>
public <S,U> Future<Tuple3<T,S,U>> zip3(java.lang.Iterable<? extends S> second, java.lang.Iterable<? extends U> third)
public <S,U,R> Future<R> zip3(java.lang.Iterable<? extends S> second, java.lang.Iterable<? extends U> third, Function3<? super T,? super S,? super U,? extends R> fn3)
public <T2,T3,T4> Future<Tuple4<T,T2,T3,T4>> zip4(java.lang.Iterable<? extends T2> second, java.lang.Iterable<? extends T3> third, java.lang.Iterable<? extends T4> fourth)
public <T2,T3,T4,R> Future<R> zip4(java.lang.Iterable<? extends T2> second, java.lang.Iterable<? extends T3> third, java.lang.Iterable<? extends T4> fourth, Function4<? super T,? super T2,? super T3,? super T4,? extends R> fn)
public <T2,R> Future<R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zippable
public <T2,R> Future<R> zip(java.util.function.BiFunction<? super T,? super T2,? extends R> fn, org.reactivestreams.Publisher<? extends T2> app)
Zippable
public static <T> Future<T> of(java.util.function.Supplier<T> s)
s
- Supplier to asynchronously populate results frompublic static <T> Future<T> of(java.util.function.Supplier<T> s, java.util.concurrent.Executor ex)
s
- Supplier to asynchronously populate results fromex
- Executro to asynchronously populate results withpublic static <T> Future<T> async(java.util.concurrent.Executor ex, java.util.function.Supplier<T> s)
public <R> Future<R> concatMap(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> mapper)
MonadicValue
Maybe.just(1).map(i->i+2).concatMap(i->Arrays.asList(()->i*3,20);
//Maybe[9]
concatMap
in interface MonadicValue<T>
mapper
- transformation functionpublic <R> Future<R> mergeMap(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> mapper)
MonadicValue
Future.ofResult(1).map(i->i+2).mergeMap(i->Flux.just(()->i*3,20);
//Future[9]
mergeMap
in interface MonadicValue<T>
mapper
- transformation functionpublic java.util.concurrent.CompletableFuture<T> getFuture()
public <R> R fold(java.util.function.Function<? super T,? extends R> success, java.util.function.Supplier<? extends R> failure)