T
- Type of wrapped future valuepublic class FutureW<T> extends java.lang.Object implements To<FutureW<T>>, ConvertableFunctor<T>, ApplicativeFunctor<T>, MonadicValue1<T>, FlatMap<T>, Filterable<T>
ApplicativeFunctor.Applicatives, ApplicativeFunctor.ApplyFunctions<T>
Value.ValueImpl<T>
Convertable.SupplierToConvertable<T>
Constructor and Description |
---|
FutureW() |
Modifier and Type | Method and Description |
---|---|
static <T,R> FutureW<R> |
accumulate(CollectionX<FutureW<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 FutureW 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)
Monoids . |
static <T,R> FutureW<R> |
accumulate(CollectionX<FutureW<T>> fts,
Reducer<R> reducer)
Asynchronously accumulate the results of Futures, a single failure will cause a failed result, using the supplied Reducer
Reducers |
static <T> FutureW<T> |
accumulate(Monoid<T> reducer,
CollectionX<FutureW<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)
Monoids
A single Failure results in a Failed Future. |
static <T,R> FutureW<R> |
accumulateSuccess(CollectionX<FutureW<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 FutureW 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)
Monoids . |
static <T,R> FutureW<R> |
accumulateSuccess(CollectionX<FutureW<T>> fts,
Reducer<R> reducer)
Asynchronously accumulate the results only from those Futures which have completed successfully.
|
static <T> FutureW<T> |
accumulateSuccess(Monoid<T> reducer,
CollectionX<FutureW<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)
Monoids . |
static <T> FutureW<T> |
allOf(FutureW<T>... fts)
Wait until all the provided FutureW's to complete
|
static <T> FutureW<T> |
anyOf(FutureW<T>... fts)
Select the first FutureW to complete
|
void |
cancel()
If not already completed, completes this FutureW 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> FutureW<U> |
cast(java.lang.Class<? extends U> type)
Cast all elements in a stream to a given type, possibly throwing a
ClassCastException . |
<R> FutureW<R> |
coflatMap(java.util.function.Function<? super MonadicValue<T>,R> mapper)
Perform a coflatMap operation.
|
FutureW<T> |
combine(java.util.function.BinaryOperator<Combiner<T>> combiner,
Combiner<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> FutureW<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
|
FutureW<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 FutureW to the provided value
|
boolean |
completeExceptionally(java.lang.Throwable e)
Complete this FutureW with an Exception
|
static <T> FutureW<T> |
empty()
An empty FutureW
|
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> FutureW<T> |
firstSuccess(FutureW<T>... fts)
Select the first Future to return with a successful result
|
<R> FutureW<R> |
flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> mapper)
A flattening transformation operation (@see
Optional.flatMap(Function) |
<R> FutureW<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> FutureW<R> |
flatMapIterable(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> FutureW<R> |
flatMapPublisher(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.
|
<R> FutureW<R> |
flatten() |
static <T> FutureW<T> |
fromIterable(java.lang.Iterable<T> iterable)
Construct a FutureW syncrhonously that contains a single value extracted from the supplied Iterable
|
static <T> FutureW<T> |
fromIterable(java.lang.Iterable<T> iterable,
java.util.concurrent.Executor ex)
Construct a FutureW asyncrhonously that contains a single value extracted from the supplied Iterable
|
static <T> FutureW<T> |
fromPublisher(org.reactivestreams.Publisher<T> pub)
Construct a FutureW syncrhonously that contains a single value extracted from the supplied reactive-streams Publisher
|
static <T> FutureW<T> |
fromPublisher(org.reactivestreams.Publisher<T> pub,
java.util.concurrent.Executor ex)
Construct a FutureW 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 FutureW 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> FutureW<T> |
future()
An empty FutureW
|
T |
get() |
boolean |
isCancelled() |
boolean |
isDone() |
boolean |
isFailed() |
boolean |
isPresent() |
boolean |
isSuccess() |
java.util.Iterator<T> |
iterator() |
<R> FutureW<R> |
map(java.util.function.Function<? super T,? extends R> fn)
Transform this functor using the supplied transformation function
|
<R> FutureW<R> |
map(java.util.function.Function<? super T,? extends R> fn,
java.util.concurrent.Executor ex)
Asyncrhonous map operation
|
<R> FutureW<R> |
map(java.util.function.Function<? super T,R> success,
java.util.function.Function<java.lang.Throwable,R> failure)
Map this FutureW differently depending on whether the previous stage
completed successfully or failed
|
<R> FutureW<R> |
matches(java.util.function.Function<Matchable.CheckValue1<T,R>,Matchable.CheckValue1<T,R>> successCase,
java.util.function.Function<Matchable.CheckValue1<java.lang.Throwable,R>,Matchable.CheckValue1<java.lang.Throwable,R>> failureCase,
java.util.function.Supplier<? extends R> otherwise)
Asychronously pattern match on the value inside this FutureW once it becomes available.
|
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.
|
FutureW<MonadicValue<T>> |
nest()
cojoin pattern.
|
Maybe<T> |
notNull()
Filter elements retaining only values which are not null
|
static <T> FutureW<T> |
of(java.util.concurrent.CompletableFuture<T> f)
Create a FutureW instance from the supplied CompletableFuture
|
static <T> FutureW<T> |
ofError(java.lang.Throwable error)
Construct a completed-with-error FutureW from the given Exception
|
static <T> FutureW<T> |
ofResult(T result)
Construct a successfully completed FutureW from the given value
|
static <T> FutureW<T> |
ofSupplier(java.util.function.Supplier<T> s)
Create a FutureW object that asyncrhonously populates using the Common
ForkJoinPool from the user provided Supplier
|
static <T> FutureW<T> |
ofSupplier(java.util.function.Supplier<T> s,
java.util.concurrent.Executor ex)
Create a FutureW 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.
|
<R> FutureW<R> |
patternMatch(java.util.function.Function<Matchable.CheckValue1<T,R>,Matchable.CheckValue1<T,R>> case1,
java.util.function.Supplier<? extends R> otherwise)
Transform the elements of this Stream with a Pattern Matching case and default value
|
FutureW<T> |
peek(java.util.function.Consumer<? super T> c)
Peek at the current value of this Functor, without transforming it
|
static <T> FutureW<ListX<T>> |
quorum(java.util.function.Predicate<Status<T>> breakout,
FutureW<T>... fts)
Block until a Quorum of results have returned as determined by the provided Predicate
|
FutureW<T> |
recover(java.util.function.Function<java.lang.Throwable,? extends T> fn)
Returns a new FutureW that, when this FutureW completes exceptionally is
executed with this FutureW exception as the argument to the supplied
function.
|
static <T> FutureW<T> |
schedule(long delay,
java.util.concurrent.ScheduledExecutorService ex,
java.util.function.Supplier<T> t)
Schedule the population of a FutureW from the provided Supplier after the specified delay.
|
static <T> FutureW<T> |
schedule(java.lang.String cron,
java.util.concurrent.ScheduledExecutorService ex,
java.util.function.Supplier<T> t)
Schedule the population of a FutureW from the provided Supplier, the provided Cron (Quartz format) expression will be used to
trigger the population of the FutureW.
|
static <T> FutureW<ListX<T>> |
sequence(CollectionX<FutureW<T>> fts)
Asynchronous sequence operation that convert a Collection of FutureWs to a FutureW with a List
|
static <T> FutureW<ReactiveSeq<T>> |
sequence(java.util.stream.Stream<FutureW<T>> fts)
Sequence operation that convert a Stream of FutureWs to a FutureW 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) |
FutureW<T> |
toFutureW() |
FutureW<T> |
toFutureWAsync() |
FutureW<T> |
toFutureWAsync(java.util.concurrent.Executor ex)
This convertable converted to a FutureW 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> FutureW<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> FutureW<T> |
unit(T unit) |
<T2,R> FutureW<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> FutureW<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> FutureW<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
|
<U> FutureW<org.jooq.lambda.tuple.Tuple2<T,U>> |
zip(org.jooq.lambda.Seq<? extends U> other)
Zip (combine) this Zippable with the supplied Seq combining both into a Tuple2
|
<U,R> FutureW<R> |
zip(org.jooq.lambda.Seq<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zip (combine) this Zippable with the supplied Seq, using the supplied combining function
|
<U> FutureW<org.jooq.lambda.tuple.Tuple2<T,U>> |
zip(java.util.stream.Stream<? extends U> other)
Zip (combine) this Zippable with the supplied Stream combining both into a Tuple2
|
<U,R> FutureW<R> |
zip(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
applyFunctions
anyM
collect, fold, fold, generate, iterate, mapReduce, newSubscriber, of, subscribe, test, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFeatureToggle, toFutureStream, toFutureStream, toLazyImmutable, toList, toListX, toMaybe, toMutable, toPBagX, toPOrderedSetX, toPQueueX, toPSetX, toPStackX, toPVectorX, toQueueX, toSetX, toSimpleReact, toSimpleReact, toSortedSetX, toTry, toTry, toTry, 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, toOptionalAtomicReference, toStream, visit
public static <T> FutureW<T> empty()
public static <T> FutureW<T> future()
public static <T> FutureW<T> anyOf(FutureW<T>... fts)
fts
- FutureWs to raceCompletableFuture.anyOf(CompletableFuture...)
public static <T> FutureW<T> allOf(FutureW<T>... fts)
fts
- FutureWs to wait onCompletableFuture.allOf(CompletableFuture...)
@SafeVarargs public static <T> FutureW<ListX<T>> quorum(java.util.function.Predicate<Status<T>> breakout, FutureW<T>... fts)
FutureW<ListX<Integer>> strings = FutureW.quorum(status -> status.getCompleted() >0, FutureW.ofSupplier(()->1),FutureW.future(),FutureW.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> FutureW<T> firstSuccess(FutureW<T>... fts)
FutureW<Integer> ft = FutureW.future();
FutureW<Integer> result = FutureW.firstSuccess(FutureW.ofSupplier(()->1),ft);
ft.complete(10);
result.get() //1
fts
- Futures to racepublic boolean completeExceptionally(java.lang.Throwable e)
e
- Throwable to complete this FutureW withCompletableFuture.completeExceptionally(Throwable)
public static <T> FutureW<T> fromPublisher(org.reactivestreams.Publisher<T> pub, java.util.concurrent.Executor ex)
ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
FutureW<Integer> future = FutureW.fromPublisher(stream,ex);
//FutureW[1]
pub
- Publisher to extract value fromex
- Executor to extract value onpublic static <T> FutureW<T> fromIterable(java.lang.Iterable<T> iterable, java.util.concurrent.Executor ex)
ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
FutureW<Integer> future = FutureW.fromIterable(stream,ex);
//FutureW[1]
iterable
- Iterable to generate a FutureW fromex
- Executor to extract value onpublic static <T> FutureW<T> fromPublisher(org.reactivestreams.Publisher<T> pub)
ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
FutureW<Integer> future = FutureW.fromPublisher(stream);
//FutureW[1]
pub
- Publisher to extract value frompublic static <T> FutureW<T> fromIterable(java.lang.Iterable<T> iterable)
ReactiveSeq<Integer> stream = ReactiveSeq.of(1,2,3);
FutureW<Integer> future = FutureW.fromIterable(stream);
//FutureW[1]
iterable
- Iterable to extract value frompublic static <T> FutureW<T> of(java.util.concurrent.CompletableFuture<T> f)
f
- CompletableFuture to wrap as a FutureW@Deprecated public static <T,X extends java.lang.Throwable> FutureW<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> FutureW<T> fromTry(Try<T,X> value)
value
- Try to populate Future frompublic static <T> FutureW<T> schedule(java.lang.String cron, java.util.concurrent.ScheduledExecutorService ex, java.util.function.Supplier<T> t)
FutureW<String> future = FutureW.schedule("* * * * * ?", Executors.newScheduledThreadPool(1), ()->"hello");
//FutureW["hello"]
cron
- Cron expression in Quartz formatex
- ScheduledExecutorService used to execute the provided Suppliert
- The Supplier to execute to populate the FutureWpublic static <T> FutureW<T> schedule(long delay, java.util.concurrent.ScheduledExecutorService ex, java.util.function.Supplier<T> t)
FutureW<String> future = FutureW.schedule(10l, Executors.newScheduledThreadPool(1), ()->"hello");
//FutureW["hello"]
delay
- Delay after which the FutureW should be populatedex
- ScheduledExecutorService used to execute the provided Suppliert
- he Supplier to execute to populate the FutureWpublic static <T> FutureW<ListX<T>> sequence(CollectionX<FutureW<T>> fts)
FutureW<ListX<Integer>> futures =FutureW.sequence(ListX.of(FutureW.ofResult(10),FutureW.ofResult(1)));
//ListX.of(10,1)
fts
- Collection of Futures to Sequence into a Future with a Listpublic static <T> FutureW<ReactiveSeq<T>> sequence(java.util.stream.Stream<FutureW<T>> fts)
FutureW<Integer> just = FutureW.ofResult(10);
FutureW<ReactiveSeq<Integer>> futures =FutureW.sequence(Stream.of(just,FutureW.ofResult(1)));
//ListX.of(10,1)
fts
- Strean of Futures to Sequence into a Future with a Streampublic static <T,R> FutureW<R> accumulateSuccess(CollectionX<FutureW<T>> fts, Reducer<R> reducer)
accumulate(CollectionX, Reducer)
if you would like a failure to result in a FutureW
with an error
FutureW<Integer> just =FutureW.of(CompletableFuture.completedFuture(10));
FutureW<Integer> none = FutureW.ofError(new NoSuchElementException());
FutureW<PSetX<Integer>> futures = FutureW.accumulateSuccess(ListX.of(just,none,FutureW.ofResult(1)),Reducers.toPSetX());
//FutureW[PSetX[10,1]]
fts
- Collection of Futures to accumulate successesreducer
- Reducer to accumulate resultspublic static <T,R> FutureW<R> accumulate(CollectionX<FutureW<T>> fts, Reducer<R> reducer)
Reducers
FutureW<Integer> just =FutureW.of(CompletableFuture.completedFuture(10));
FutureW<Integer> none = FutureW.ofError(new NoSuchElementException());
FutureW<PSetX<Integer>> futures = FutureW.accumulateSuccess(ListX.of(just,none,FutureW.ofResult(1)),Reducers.toPSetX());
//FutureW[PSetX[10,1]]
fts
- Collection of Futures to accumulate successesreducer
- Reducer to accumulate resultspublic static <T,R> FutureW<R> accumulateSuccess(CollectionX<FutureW<T>> fts, java.util.function.Function<? super T,R> mapper, Monoid<R> reducer)
Monoids
.
FutureW<String> future = FutureW.accumulate(ListX.of(FutureW.ofResult(10),FutureW.ofResult(1)),i->""+i,Monoids.stringConcat);
//FutureW["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> FutureW<T> accumulateSuccess(Monoid<T> reducer, CollectionX<FutureW<T>> fts)
Monoids
.
FutureW<Integer> just =FutureW.of(CompletableFuture.completedFuture(10));
FutureW<Integer> future =FutureW.accumulate(Monoids.intSum, ListX.of(just,FutureW.ofResult(1)));
//FutureW[11]
fts
- Collection of Futures to accumulate successesreducer
- Monoid to combine values from each Futurepublic static <T,R> FutureW<R> accumulate(CollectionX<FutureW<T>> fts, java.util.function.Function<? super T,R> mapper, Monoid<R> reducer)
Monoids
.
A single Failure results in a Failed Future.
FutureW<String> future = FutureW.accumulate(ListX.of(FutureW.ofResult(10),FutureW.ofResult(1)),i->""+i,Monoids.stringConcat);
//FutureW["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> FutureW<T> accumulate(Monoid<T> reducer, CollectionX<FutureW<T>> fts)
Monoids
A single Failure results in a Failed Future.
FutureW<Integer> future =FutureW.accumulate(Monoids.intSum,ListX.of(just,FutureW.ofResult(1)));
//FutureW[11]
fts
- Collection of Futures to accumulate successesreducer
- Monoid to combine values from each Futurepublic <R> FutureW<R> matches(java.util.function.Function<Matchable.CheckValue1<T,R>,Matchable.CheckValue1<T,R>> successCase, java.util.function.Function<Matchable.CheckValue1<java.lang.Throwable,R>,Matchable.CheckValue1<java.lang.Throwable,R>> failureCase, java.util.function.Supplier<? extends R> otherwise)
import static com.aol.cyclops.control.Matchable.otherwise;
import static com.aol.cyclops.control.Matchable.then;
import static com.aol.cyclops.control.Matchable.when;
import static com.aol.cyclops.util.function.Predicates.instanceOf;
FutureW.ofResult(10).matches(c->c.is(when(10),then("hello")),
c->c.is(when(instanceOf(Throwable.class)), then("error")),
otherwise("miss"));
//FutureW["hello"]
FutureW.ofResult(10).matches(c->c.is(when(10),then("hello")).is(when(2),then("hello")),
c->c.is(when(Predicates.instanceOf(Throwable.class)), then("error")),
otherwise("miss"));
//FutureW["hello"]
FutureW.ofResult(10).matches(c->c.is(when(1),then("hello"))
.is(when(2),then(()->"hello"))
.is(when(3),then(()->"hello")),
c->c.is(when(Predicates.instanceOf(Throwable.class)), then("error")),
otherwise("miss"));
//FutureW["miss"]
successCase
- Pattern matching function executed if this FutureW completes the previous stage successfullyfailureCase
- Pattern matching function executed if this FutureW completes the previous stage with an exceptionotherwise
- Supplier used to provide a value if the selecting pattern matching function fails to find a matchpublic <R> FutureW<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>
coflatMap
in interface MonadicValue1<T>
mapper
- Mapping / transformation functionpublic FutureW<MonadicValue<T>> nest()
MonadicValue
nest
in interface MonadicValue<T>
public FutureW<T> combineEager(Monoid<T> monoid, MonadicValue<? extends T> v2)
MonadicValue1
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 MonadicValue1<T>
public <R> FutureW<R> map(java.util.function.Function<? super T,? extends R> fn)
Functor
of(1,2,3).map(i->i*2)
//[2,4,6]
map
in interface ConvertableFunctor<T>
map
in interface Functor<T>
map
in interface MonadicValue<T>
map
in interface MonadicValue1<T>
fn
- Transformation functionpublic <R> FutureW<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 <R> FutureW<R> patternMatch(java.util.function.Function<Matchable.CheckValue1<T,R>,Matchable.CheckValue1<T,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<T>
case1
- Function to generate a case (or chain of cases as a single case)otherwise
- Value if supplied case doesn't matchpublic T get()
get
in interface Convertable<T>
get
in interface java.util.function.Supplier<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 FutureW topublic boolean isFailed()
public java.util.Iterator<T> iterator()
public <T> FutureW<T> unit(T unit)
unit
in interface MonadicValue<T>
unit
in interface MonadicValue1<T>
unit
in interface Unit<T>
public ReactiveSeq<T> stream()
public <R> FutureW<R> flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> mapper)
MonadicValue1
Optional.flatMap(Function)
Eval.now(1).map(i->i+2).flatMap(i->Eval.later(()->i*3);
//Eval[9]
flatMap
in interface MonadicValue1<T>
mapper
- transformation functionpublic <R> FutureW<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 FutureW<T> toFutureW()
toFutureW
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 FutureW<T> recover(java.util.function.Function<java.lang.Throwable,? extends T> fn)
FutureW.ofError(new RuntimeException())
.recover(__ -> true)
//FutureW[true]
fn
- the function to use to compute the value of the returned
FutureW if this FutureW completed exceptionallypublic <R> FutureW<R> map(java.util.function.Function<? super T,R> success, java.util.function.Function<java.lang.Throwable,R> failure)
FutureW.ofResult(1)
.map(i->i*2,e->-1);
//FutureW[2]
success
- Mapping function for successful outcomesfailure
- Mapping function for failed outcomespublic <U> FutureW<U> cast(java.lang.Class<? extends U> type)
Functor
ClassCastException
.
// ClassCastException ReactiveSeq.of(1, "a", 2, "b", 3).cast(Integer.class)public FutureW<T> peek(java.util.function.Consumer<? super T> c)
Functor
of(1,2,3).map(System.out::println)
1
2
3
public <R> FutureW<R> trampoline(java.util.function.Function<? super T,? 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<T>
mapper
- TCO Transformation functionpublic java.lang.String toString()
toString
in class java.lang.Object
public static <T> FutureW<T> ofResult(T result)
result
- To wrap inside a FutureWpublic static <T> FutureW<T> ofError(java.lang.Throwable error)
error
- To wrap inside a FutureWpublic boolean isPresent()
isPresent
in interface Convertable<T>
public java.lang.String mkString()
Value
public Maybe<T> filter(java.util.function.Predicate<? super T> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[3]
filter
in interface Filterable<T>
fn
- to filter elements by, retaining matchespublic <U> Maybe<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<T>
public Maybe<T> filterNot(java.util.function.Predicate<? super T> fn)
Filterable
of(1,2,3).filter(i->i>2);
//[1,2]
filterNot
in interface Filterable<T>
fn
- to filter elements by, retaining matchespublic Maybe<T> notNull()
Filterable
of(1,2,null,4).nonNull();
//[1,2,4]
notNull
in interface Filterable<T>
public java.util.Optional<T> toOptional()
toOptional
in interface Convertable<T>
public FutureW<T> toFutureWAsync()
toFutureWAsync
in interface Convertable<T>
public FutureW<T> toFutureWAsync(java.util.concurrent.Executor ex)
Convertable
toFutureWAsync
in interface Convertable<T>
ex
- Executor to execute the conversion onpublic <T2,R> FutureW<R> combine(Value<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Combiner
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
public <T2,R> FutureW<R> zip(java.lang.Iterable<? extends T2> app, java.util.function.BiFunction<? super T,? super T2,? extends R> fn)
Zippable
public <T2,R> FutureW<R> zip(java.util.function.BiFunction<? super T,? super T2,? extends R> fn, org.reactivestreams.Publisher<? extends T2> app)
Zippable
public static <T> FutureW<T> ofSupplier(java.util.function.Supplier<T> s)
s
- Supplier to asynchronously populate results frompublic static <T> FutureW<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> FutureW<R> zip(org.jooq.lambda.Seq<? extends U> other, java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zippable
public <U,R> FutureW<R> zip(java.util.stream.Stream<? extends U> other, java.util.function.BiFunction<? super T,? super U,? extends R> zipper)
Zippable
public <U> FutureW<org.jooq.lambda.tuple.Tuple2<T,U>> zip(java.util.stream.Stream<? extends U> other)
Zippable
public <U> FutureW<org.jooq.lambda.tuple.Tuple2<T,U>> zip(org.jooq.lambda.Seq<? extends U> other)
Zippable
public <U> FutureW<org.jooq.lambda.tuple.Tuple2<T,U>> zip(java.lang.Iterable<? extends U> other)
Zippable
public <R> FutureW<R> flatMapIterable(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends R>> mapper)
MonadicValue1
Maybe.just(1).map(i->i+2).flatMapIterable(i->Arrays.asList(()->i*3,20);
//Maybe[9]
flatMapIterable
in interface MonadicValue1<T>
mapper
- transformation functionpublic <R> FutureW<R> flatMapPublisher(java.util.function.Function<? super T,? extends org.reactivestreams.Publisher<? extends R>> mapper)
MonadicValue1
FutureW.ofResult(1).map(i->i+2).flatMapPublisher(i->Flux.just(()->i*3,20);
//FutureW[9]
flatMapPublisher
in interface MonadicValue1<T>
mapper
- transformation functionpublic FutureW<T> combine(java.util.function.BinaryOperator<Combiner<T>> combiner, Combiner<T> app)
Combiner
combine
in interface Combiner<T>
Semigroup
,
Semigroups
,
Monoid
,
To lift any Semigroup (or monoid) up to handling Applicatives use the combineApplicatives operator in Semigroups
{@see com.aol.cyclops.Semigroups#combineApplicatives(BiFunction) } or Monoids
{ {@see com.aol.cyclops.Monoids#combineApplicatives(java.util.function.Function, com.aol.cyclops.Monoid)
}
{@code
BinaryOperator> sumMaybes = Semigroups.combineScalarFunctors(Semigroups.intSum);
Maybe.just(1)
.combine(sumMaybes, Maybe.just(5))
//Maybe.just(6));
}