T
- Type of wrapped future valuepublic class Future<T> extends java.lang.Object implements To<Future<T>>, MonadicValue<T>, Higher<Future.µ,T>
Modifier and Type | Class and Description |
---|---|
static class |
Future.µ |
static class |
Future.Instances
Companion class for creating Type Class instances for working with FutureWs
|
Value.ValueImpl<T>
Convertable.SupplierToConvertable<T>
Fn0.FunctionalOperations<R>, Fn0.SupplierKind<R>
Constructor and Description |
---|
Future() |
Modifier and Type | Method and Description |
---|---|
static <T,R> Future<R> |
accumulate(CollectionX<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(CollectionX<Future<T>> fts,
Reducer<R> 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,
CollectionX<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(CollectionX<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(CollectionX<Future<T>> fts,
Reducer<R> reducer)
Asynchronously accumulate the results only from those Futures which have completed successfully.
|
static <T> Future<T> |
accumulateSuccess(Monoid<T> reducer,
CollectionX<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
|
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 |
<U> Future<U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
<R> Future<R> |
coflatMap(java.util.function.Function<? super MonadicValue<T>,R> mapper)
Perform a coflatMap operation.
|
<T2,R> Future<R> |
combine(Value<? extends T2> app,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Lazily combine this ApplicativeFunctor with the supplied value via the supplied BiFunction
Example
|
Future<T> |
combineEager(Monoid<T> monoid,
MonadicValue<? extends T> v2)
Eagerly combine two MonadicValues using the supplied monoid (@see ApplicativeFunctor for type appropraite i.e.
|
void |
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
|
static <T> Future<T> |
empty()
An empty Future
|
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
|
<R> Future<R> |
flatMapI(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.
|
<R> Future<R> |
flatMapP(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.
|
static <R> Future<R> |
flatten(Future<? extends Future<R>> nested) |
<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,
Fn3<? 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,
Fn3<? super T,? super R1,? super R2,java.lang.Boolean> filterFunction,
Fn3<? 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,
Fn3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3,
Fn4<? 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,
Fn3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3,
Fn4<? super T,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction,
Fn4<? 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<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 asyncrhonously 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,X extends java.lang.Throwable> |
fromTry(Try<T,X> value,
java.util.concurrent.Executor ex)
Deprecated.
|
static <T> Future<T> |
future()
An empty Future
|
T |
get()
Apply this function to the arguments.
|
java.util.concurrent.CompletableFuture<T> |
getFuture() |
boolean |
isCancelled() |
boolean |
isDone() |
boolean |
isFailed() |
boolean |
isPresent() |
boolean |
isSuccess() |
java.util.Iterator<T> |
iterator() |
<W extends WitnessType<W>> |
liftM(W witness) |
<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 map 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
|
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> |
narrowK(Higher<Future.µ,T> future)
Convert the raw Higher Kinded Type for FutureType types into the FutureType type definition class
|
Future<MonadicValue<T>> |
nest()
cojoin pattern.
|
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> |
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
|
static <T> Future<T> |
ofSupplier(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> |
ofSupplier(java.util.function.Supplier<T> s,
java.util.concurrent.Executor ex)
Create a Future object that asyncrhonously populates using the provided
Executor and Supplier
|
<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
|
static <T> Future<ListX<T>> |
quorum(java.util.function.Predicate<Status<T>> breakout,
Future<T>... fts)
Block until a Quorum of results have returned as determined by the provided Predicate
|
Future<T> |
recover(java.util.function.Function<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.
|
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<ListX<T>> |
sequence(CollectionX<Future<T>> fts)
Asynchronous sequence operation that convert a Collection of FutureWs to a Future with a List
|
static <T> Future<ReactiveSeq<T>> |
sequence(java.util.stream.Stream<? extends Future<T>> fts)
Sequence operation that convert a Stream of FutureWs to a Future with a Stream
|
ReactiveSeq<T> |
stream() |
java.util.concurrent.CompletableFuture<T> |
toCompletableFuture() |
java.util.concurrent.CompletableFuture<T> |
toCompletableFutureAsync() |
java.util.concurrent.CompletableFuture<T> |
toCompletableFutureAsync(java.util.concurrent.Executor exec) |
Future<T> |
toFuture() |
Future<T> |
toFutureWAsync() |
Future<T> |
toFutureWAsync(java.util.concurrent.Executor ex)
This convertable converted to a Future asyncrhonously using the supplied Executor
|
Ior<java.lang.Throwable,T> |
toIor()
Return an Ior that can be this object or a Ior.primary or Ior.secondary
|
java.util.Optional<T> |
toOptional() |
java.lang.String |
toString() |
Xor<java.lang.Throwable,T> |
toXor() |
<R> Future<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
|
<T> Future<T> |
unit(T unit) |
<R> R |
visit(java.util.function.Function<T,R> success,
java.util.function.Function<java.lang.Throwable,R> failure)
Blocking analogue to visitAsync.
|
<R> Future<R> |
visitAsync(java.util.function.Function<T,R> success,
java.util.function.Function<java.lang.Throwable,R> failure)
Non-blocking visit on the state of this Future
|
Future<T> |
zip(java.util.function.BinaryOperator<Zippable<T>> combiner,
Zippable<T> app)
Combine two applicatives together using the provided BinaryOperator (Semigroup, Monoid and Reducer all
extend BinaryOperator - checkout Semigroups and Monoids for a large number of canned combinations).
|
<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<org.jooq.lambda.tuple.Tuple2<T,U>> |
zip(java.lang.Iterable<? extends U> other)
Zip (combine) this Zippable with the supplied Iterable combining both into a Tuple2
|
<T2,R> Future<R> |
zipP(org.reactivestreams.Publisher<? extends T2> app,
java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zip (combine) this Zippable with the supplied Publisher, using the supplied combining function
|
<U> Future<org.jooq.lambda.tuple.Tuple2<T,U>> |
zipS(java.util.stream.Stream<? extends U> other)
Zip (combine) this Zippable with the supplied Stream combining both into a Tuple2
|
<U,R> Future<R> |
zipS(java.util.stream.Stream<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zip (combine) this Zippable with the supplied Stream, using the supplied combining function
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
flatMapS
apply, generate, iterate, newSubscriber, of, subscribe, test, toEvalAlways, toEvalLater, toEvalNow, toMaybe, toTry, toTry, toTry, toXor
endsWith, endsWithIterable, findAny, findFirst, firstValue, foldLeft, foldLeft, foldLeft, foldLeft, 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, xMatch
futureStream, getStreamable, isEmpty, jdkStream, reactiveSeq, reveresedJDKStream, reveresedStream
collect, fromSupplier, orElse, orElseGet, orElseThrow, toStream, visit
andThen, fnTo, functionOps, lift, lift, liftF, liftOpt, liftTry, memoize, memoize, run, suspend, λ, λv
zip3, zip3, zip4, zip4, zipP, zipWith, zipWithP, zipWithS
retry, retry
public <W extends WitnessType<W>> FutureT<W,T> liftM(W witness)
public static <T> Future<T> narrowK(Higher<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
- FutureWs to raceCompletableFuture.anyOf(CompletableFuture...)
public static <T> Future<T> allOf(Future<T>... fts)
fts
- FutureWs to wait onCompletableFuture.allOf(CompletableFuture...)
@SafeVarargs public static <T> Future<ListX<T>> quorum(java.util.function.Predicate<Status<T>> breakout, Future<T>... fts)
Future<ListX<Integer>> strings = Future.quorum(status -> status.getCompleted() >0, Future.ofSupplier(()->1),Future.future(),Future.future());
strings.get().size()
//1
breakout
- Predicate that determines whether the block should be
continued or removedfts
- FutureWs to wait on results from@SafeVarargs public static <T> Future<T> firstSuccess(Future<T>... fts)
Future<Integer> ft = Future.future();
Future<Integer> result = Future.firstSuccess(Future.ofSupplier(()->1),ft);
ft.complete(10);
result.get() //1
fts
- Futures to racepublic boolean completeExceptionally(java.lang.Throwable e)
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<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 Future@Deprecated public static <T,X extends java.lang.Throwable> Future<T> fromTry(Try<T,X> value, java.util.concurrent.Executor ex)
value
- Try to populate Future fromex
- Executor to executepublic 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<ListX<T>> sequence(CollectionX<Future<T>> fts)
Future<ListX<Integer>> futures =Future.sequence(ListX.of(Future.ofResult(10),Future.ofResult(1)));
//ListX.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)));
//ListX.of(10,1)
fts
- Strean of Futures to Sequence into a Future with a Streampublic static <T,R> Future<R> accumulateSuccess(CollectionX<Future<T>> fts, Reducer<R> reducer)
accumulate(CollectionX, 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<PSetX<Integer>> futures = Future.accumulateSuccess(ListX.of(just,none,Future.ofResult(1)),Reducers.toPSetX());
//Future[PSetX[10,1]]
fts
- Collection of Futures to accumulate successesreducer
- Reducer to accumulate resultspublic static <T,R> Future<R> accumulate(CollectionX<Future<T>> fts, Reducer<R> reducer)
cyclops2.Reducers
Future<Integer> just =Future.of(CompletableFuture.completedFuture(10));
Future<Integer> none = Future.ofError(new NoSuchElementException());
Future<PSetX<Integer>> futures = Future.accumulateSuccess(ListX.of(just,none,Future.ofResult(1)),Reducers.toPSetX());
//Future[PSetX[10,1]]
fts
- Collection of Futures to accumulate successesreducer
- Reducer to accumulate resultspublic static <T,R> Future<R> accumulateSuccess(CollectionX<Future<T>> fts, java.util.function.Function<? super T,R> mapper, Monoid<R> reducer)
cyclops2.Monoids
.
Future<String> future = Future.accumulate(ListX.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, CollectionX<Future<T>> fts)
cyclops2.Monoids
.
Future<Integer> just =Future.of(CompletableFuture.completedFuture(10));
Future<Integer> future =Future.accumulate(Monoids.intSum, ListX.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(CollectionX<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(ListX.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, CollectionX<Future<T>> fts)
cyclops2.Monoids
A single Failure results in a Failed Future.
Future<Integer> future =Future.accumulate(Monoids.intSum,ListX.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, Fn3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3, Fn4<? 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, Fn3<? super T,? super R1,? super R2,? extends MonadicValue<R3>> value3, Fn4<? super T,? super R1,? super R2,? super R3,java.lang.Boolean> filterFunction, Fn4<? 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 apply 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, Fn3<? 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, Fn3<? super T,? super R1,? super R2,java.lang.Boolean> filterFunction, Fn3<? 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 apply 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>
filterFunction
- Filter to apply 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 elementspublic <R> Future<R> visitAsync(java.util.function.Function<T,R> success, java.util.function.Function<java.lang.Throwable,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> R visit(java.util.function.Function<T,R> success, java.util.function.Function<java.lang.Throwable,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> coflatMap(java.util.function.Function<? super MonadicValue<T>,R> mapper)
MonadicValue
Maybe.none().coflatMap(m -> m.isPresent() ? m.get() : 10);
//Maybe[10]
coflatMap
in interface MonadicValue<T>
mapper
- Mapping / transformation functionpublic Future<MonadicValue<T>> nest()
MonadicValue
nest
in interface MonadicValue<T>
public Future<T> combineEager(Monoid<T> monoid, MonadicValue<? extends T> v2)
MonadicValue
Monoid<Integer> add = Monoid.of(1,Semigroups.intSum);
Maybe.of(10).combineEager(add,Maybe.none());
//Maybe[10]
Maybe.none().combineEager(add,Maybe.of(10));
//Maybe[10]
Maybe.none().combineEager(add,Maybe.none());
//Maybe.none()
Maybe.of(10).combineEager(add,Maybe.of(10));
//Maybe[20]
Monoid<Integer> firstNonNull = Monoid.of(null , Semigroups.firstNonNull());
Maybe.of(10).combineEager(firstNonNull,Maybe.of(10));
//Maybe[10]
combineEager
in interface MonadicValue<T>
public <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 MonadicValue<T>
map
in interface Transformable<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 T get()
org.jooq.lambda.function.Function0
get
in interface Convertable<T>
get
in interface java.util.function.Supplier<T>
get
in interface org.jooq.lambda.function.Function0<T>
public boolean isSuccess()
public boolean isDone()
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 void complete(T value)
value
- Value to set this Future topublic boolean isFailed()
public java.util.Iterator<T> iterator()
public <T> Future<T> unit(T unit)
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 Ior<java.lang.Throwable,T> toIor()
Value
public Future<T> toFuture()
toFuture
in interface Convertable<T>
public java.util.concurrent.CompletableFuture<T> toCompletableFuture()
toCompletableFuture
in interface Convertable<T>
public java.util.concurrent.CompletableFuture<T> toCompletableFutureAsync()
toCompletableFutureAsync
in interface Convertable<T>
public java.util.concurrent.CompletableFuture<T> toCompletableFutureAsync(java.util.concurrent.Executor exec)
toCompletableFutureAsync
in interface Convertable<T>
exec
- Executor to asyncrhonously populate the CompletableFuturepublic Future<T> recover(java.util.function.Function<java.lang.Throwable,? extends T> fn)
Future.ofError(new RuntimeException())
.recover(__ -> true)
//Future[true]
fn
- the function to use to compute the value of the returned
Future if this Future completed exceptionallypublic <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 <U> Future<U> cast(java.lang.Class<? extends U> type)
Transformable
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)cast
in interface Transformable<T>
public 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 <R> Future<R> trampoline(java.util.function.Function<? super T,? extends Trampoline<? extends R>> mapper)
Transformable
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 Transformable<T>
mapper
- TCO Transformation functionpublic 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 boolean isPresent()
isPresent
in interface Convertable<T>
public 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 java.util.Optional<T> toOptional()
toOptional
in interface Convertable<T>
public Future<T> toFutureWAsync()
toFutureWAsync
in interface Convertable<T>
public Future<T> toFutureWAsync(java.util.concurrent.Executor ex)
Convertable
toFutureWAsync
in interface Convertable<T>
ex
- Executor to execute the conversion onpublic <T2,R> Future<R> combine(Value<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
MonadicValue
Maybe<Integer> some = Maybe.just(10);
just.combine(Eval.now(20), this::add);
//Some[30]
Maybe<Integer> none = Maybe.none();
none.combine(Eval.now(20), this::add);
//None
combine
in interface MonadicValue<T>
app
- Value to combine with this one.fn
- BiFunction to combine thempublic <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> zipP(org.reactivestreams.Publisher<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zippable
public static <T> Future<T> ofSupplier(java.util.function.Supplier<T> s)
s
- Supplier to asynchronously populate results frompublic static <T> Future<T> ofSupplier(java.util.function.Supplier<T> s, java.util.concurrent.Executor ex)
s
- Supplier to asynchronously populate results fromex
- Executro to asynchronously populate results withpublic <U,R> Future<R> zipS(java.util.stream.Stream<? extends U> other, java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zippable
public <U> Future<org.jooq.lambda.tuple.Tuple2<T,U>> zipS(java.util.stream.Stream<? extends U> other)
Zippable
public <U> Future<org.jooq.lambda.tuple.Tuple2<T,U>> zip(java.lang.Iterable<? extends U> other)
Zippable
public <R> Future<R> flatMapI(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> mapper)
MonadicValue
Maybe.just(1).map(i->i+2).flatMapI(i->Arrays.asList(()->i*3,20);
//Maybe[9]
flatMapI
in interface MonadicValue<T>
mapper
- transformation functionpublic <R> Future<R> flatMapP(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> mapper)
MonadicValue
FutureW.ofResult(1).map(i->i+2).flatMapP(i->Flux.just(()->i*3,20);
//FutureW[9]
flatMapP
in interface MonadicValue<T>
mapper
- transformation functionpublic Future<T> zip(java.util.function.BinaryOperator<Zippable<T>> combiner, Zippable<T> app)
Zippable
zip
in interface Zippable<T>
Semigroup
,
Semigroups
,
Monoid
,
To lift any Semigroup (or monoid) up to handling Applicatives use the combineApplicatives operator in Semigroups
{@see com.aol.cyclops2.Semigroups#combineApplicatives(BiFunction) } or Monoids
{ {@see com.aol.cyclops2.Monoids#combineApplicatives(java.util.function.Function, com.aol.cyclops2.function.Monoid)
}
{@code
BinaryOperator> sumMaybes = Semigroups.combineScalarFunctors(Semigroups.intSum);
Maybe.just(1).zip(sumMaybes, Maybe.just(5))
//Maybe.just(6));
}
public java.util.concurrent.CompletableFuture<T> getFuture()