T
- Success data typeX
- Error data typepublic static class Try.Success<T,X extends java.lang.Throwable> extends java.lang.Object implements Try<T,X>
Try.AndFinally<T,V,X extends java.lang.Throwable>, Try.CheckedConsumer<T,X extends java.lang.Throwable>, Try.CheckedFunction<T,R,X extends java.lang.Throwable>, Try.CheckedRunnable<X extends java.lang.Throwable>, Try.CheckedSupplier<T,X extends java.lang.Throwable>, Try.Failure<T,X extends java.lang.Throwable>, Try.Init<X extends java.lang.Throwable>, Try.MyFinallyBlock<T,V,X extends java.lang.Throwable>, Try.MyInit<X extends java.lang.Throwable>, Try.MyTryCatch<V,X extends java.lang.Throwable>, Try.Success<T,X extends java.lang.Throwable>, Try.TryCatch<V,X extends java.lang.Throwable>
Value.ValueImpl<T>
Convertable.SupplierToConvertable<T>
Fn0.FunctionalOperations<R>, Fn0.Instances, Fn0.SupplierKind<R>
Constructor and Description |
---|
Success() |
Modifier and Type | Method and Description |
---|---|
<T2,R> Try<R,X> |
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
|
boolean |
equals(java.lang.Object o) |
X |
failureGet() |
Maybe<T> |
filter(java.util.function.Predicate<? super T> p)
Keep only elements for which the supplied predicates hold
e.g.
|
<R> Try<R,X> |
flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> fn)
A flattening transformation operation (@see
Optional.flatMap(Function) |
void |
forEach(java.util.function.Consumer<? super T> consumer) |
void |
forEachFailed(java.util.function.Consumer<? super X> consumer) |
T |
get()
Apply this function to the arguments.
|
int |
hashCode() |
boolean |
isFailure() |
boolean |
isSuccess() |
<R> Try<R,X> |
map(java.util.function.Function<? super T,? extends R> fn)
Transform this functor using the supplied transformation function
|
static <T,X extends java.lang.Throwable> |
of(T value,
java.lang.Class<? extends java.lang.Throwable>[] classes)
Return a Try that will catch specified exceptions when map / flatMap called
For use with liftM / liftM2 and For Comprehensions (when Try is at the top level)
|
Try<T,X> |
onFail(java.lang.Class<? extends X> t,
java.util.function.Consumer<X> consumer) |
Try<T,X> |
onFail(java.util.function.Consumer<? super X> consumer) |
T |
orElse(T value)
Get the contained value or else the provided alternative
|
T |
orElseGet(java.util.function.Supplier<? extends T> value)
An equivalent operation to
Optional.orElseGet(Supplier)
Returns a value generated by the provided Supplier if this Convertable is empty or
contains a null value. |
Try.Success<T,X> |
recover(java.util.function.Function<? super X,? extends T> fn) |
Try.Success<T,X> |
recoverFor(java.lang.Class<? extends X> t,
java.util.function.Function<? super X,? extends T> fn)
Recover if exception is of specified type
|
Try<T,X> |
recoverWith(java.util.function.Function<? super X,? extends Try<T,X>> fn)
flatMap recovery
|
Try.Success<T,X> |
recoverWithFor(java.lang.Class<? extends X> t,
java.util.function.Function<? super X,? extends Try.Success<T,X>> fn)
FlatMap recovery function if exception is of specified type
|
ReactiveSeq<T> |
stream() |
void |
throwException()
Throw exception if Failure, do nothing if success
|
java.util.Optional<X> |
toFailedOptional() |
java.util.stream.Stream<X> |
toFailedStream() |
Ior<X,T> |
toIor()
Return an Ior that can be this object or a Ior.primary or Ior.secondary
|
java.util.Optional<T> |
toOptional() |
Xor<X,T> |
toXor() |
<R> R |
visit(java.util.function.Function<? super T,? extends R> success,
java.util.function.Function<? super X,? extends R> failure)
Execute one function conditional on Try state (Success / Failure)
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
anyM, cast, catchExceptions, coflatMap, combine, failure, filterNot, flatMapS, flatten, forEach2, forEach2, forEach3, forEach3, forEach4, forEach4, fromIterable, fromPublisher, fromPublisher, isPresent, iterator, nest, notNull, ofType, peek, peekFailed, retry, retry, runWithCatch, success, toTry, toXorWithError, trampoline, unit, withCatch, zip, zip, zip, zip3, zip3, zip4, zip4, zipP, zipP, zipS, zipS, zipWith, zipWithP, zipWithS
combineEager, flatMapI, flatMapP
apply, generate, iterate, mkString, newSubscriber, of, subscribe, test, toEvalAlways, toEvalLater, toEvalNow, toMaybe, 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, orElseThrow, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFuture, toFutureWAsync, toFutureWAsync, toStream, visit
public Ior<X,T> toIor()
Value
public T get()
org.jooq.lambda.function.Function0
get
in interface Convertable<T>
get
in interface Try<T,X extends java.lang.Throwable>
get
in interface java.util.function.Supplier<T>
get
in interface org.jooq.lambda.function.Function0<T>
public static <T,X extends java.lang.Throwable> Try.Success<T,X> of(T value, java.lang.Class<? extends java.lang.Throwable>[] classes)
Try
public <R> Try<R,X> 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>
map
in interface Try<T,X extends java.lang.Throwable>
fn
- Map success value from T to R. Do nothing if Failure (return this)public <R> Try<R,X> flatMap(java.util.function.Function<? super T,? extends MonadicValue<? extends R>> fn)
MonadicValue
Optional.flatMap(Function)
Eval.now(1).map(i->i+2).flatMap(i->Eval.later(()->i*3);
//Eval[9]
public Maybe<T> filter(java.util.function.Predicate<? super T> p)
Filters
of(1,2,3).filter(i->i>2);
//[3]
filter
in interface Filters<T>
filter
in interface MonadicValue<T>
filter
in interface Try<T,X extends java.lang.Throwable>
p
- Convert a Success to a Failure (with a null value for Exception) if predicate does not hold.
Do nothing to a Failurepublic Try.Success<T,X> recover(java.util.function.Function<? super X,? extends T> fn)
public Try<T,X> recoverWith(java.util.function.Function<? super X,? extends Try<T,X>> fn)
Try
recoverWith
in interface Try<T,X extends java.lang.Throwable>
fn
- Recovery FlatMap function. Map from a failure to a Successpublic Try.Success<T,X> recoverFor(java.lang.Class<? extends X> t, java.util.function.Function<? super X,? extends T> fn)
Try
recoverFor
in interface Try<T,X extends java.lang.Throwable>
t
- Type of exception to match againstfn
- Recovery functionpublic Try.Success<T,X> recoverWithFor(java.lang.Class<? extends X> t, java.util.function.Function<? super X,? extends Try.Success<T,X>> fn)
Try
recoverWithFor
in interface Try<T,X extends java.lang.Throwable>
t
- Type of exception to match againstfn
- Recovery FlatMap function. Map from a failure to a Successpublic T orElse(T value)
Convertable
public X failureGet()
failureGet
in interface Try<T,X extends java.lang.Throwable>
public T orElseGet(java.util.function.Supplier<? extends T> value)
Convertable
Optional.orElseGet(Supplier)
Returns a value generated by the provided Supplier if this Convertable is empty or
contains a null value.public java.util.Optional<T> toOptional()
toOptional
in interface Convertable<T>
toOptional
in interface Try<T,X extends java.lang.Throwable>
public ReactiveSeq<T> stream()
public boolean isSuccess()
public boolean isFailure()
public void forEach(java.util.function.Consumer<? super T> consumer)
public Try<T,X> onFail(java.lang.Class<? extends X> t, java.util.function.Consumer<X> consumer)
public void throwException()
Try
throwException
in interface Try<T,X extends java.lang.Throwable>
public java.util.Optional<X> toFailedOptional()
toFailedOptional
in interface Try<T,X extends java.lang.Throwable>
public java.util.stream.Stream<X> toFailedStream()
toFailedStream
in interface Try<T,X extends java.lang.Throwable>
public void forEachFailed(java.util.function.Consumer<? super X> consumer)
forEachFailed
in interface Try<T,X extends java.lang.Throwable>
consumer
- Accept value if Failure / not called on Failurepublic <T2,R> Try<R,X> 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
public <R> R visit(java.util.function.Function<? super T,? extends R> success, java.util.function.Function<? super X,? extends R> failure)
Try
Try<Integer> result = this.execute();
this.logState(result.visit(t->"value is " +t,e->"error is "+e.getMessage());
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object