E - on failure there will be a NonEmptyList of error instances with an error value of this type.A - when successful there will be a contained value of this type.public abstract class Result<E,A> extends Object
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
<F> Result<F,A> |
errorMap(java.util.function.Function<E,F> errorMapper)
Modifies the error type of the result, returning a new
Result |
static <E,S> Result<E,S> |
failure(E error,
E... errors)
Factory method to creates a Failed
Result from a array value of error |
static <E,S> Result<E,S> |
failure(NonEmptyList<E> errors)
Factory method to creates a Failed
Result from a {@link NonEmptyList< E >}} |
Optional<NonEmptyList<E>> |
failureReasons()
If this is a failure, return the error reasons for that failure, if not return nothing.
|
<T> Result<E,T> |
flatMap(java.util.function.Function<A,Result<E,T>> mapper)
Runs the given function on the contents value this Result, returning a new
Result with the
extracted reason extracted from the functions returned Result<E, T> |
abstract <T> T |
fold(java.util.function.Function<NonEmptyList<E>,T> f,
java.util.function.Function<A,T> s)
Turn this Result into a destination type by supplying functions
from the list of failure errors, or a function from the contained value.
|
A |
getOrElse(A defaultValue)
Return the value contained within this
Result if the isSuccess() is true else
return the default value provided. |
void |
ifSuccessful(java.util.function.Consumer<A> consumer)
If a value is present, invoke the specified consumer with the value,
otherwise do nothing.
|
boolean |
isFailure()
Return true if this Result is a failure.
|
abstract boolean |
isSuccess()
Return true if this Result is a success.
|
<T> Result<E,T> |
map(java.util.function.Function<A,T> mapper)
Runs the given function on the contents value this Result, returning a new
Result with the
output value the result of that function. |
static <E,S> Result<E,S> |
success(S s)
Factory method to creates a succesful
Result from a value. |
public static <E,S> Result<E,S> success(S s)
Result from a value.E - The error type for failures.S - when successful there will be a contained value this type.s - value that will be lifted into this ResultResult containing value provided.@SafeVarargs public static <E,S> Result<E,S> failure(E error, E... errors)
Result from a array value of errorE - The error type for failures.S - when successful there will be a contained value this type.error - the first cause of Result to be failederrors - a variable argument list of further causes of failureResult containing the failed errorspublic static <E,S> Result<E,S> failure(NonEmptyList<E> errors)
Result from a {@link NonEmptyList< E >}}E - The error type for failures.S - when successful there will be a contained value this type.errors - what caused this Result to failedResult containing the failed errorspublic abstract boolean isSuccess()
public final boolean isFailure()
public A getOrElse(A defaultValue)
Result if the isSuccess() is true else
return the default value provided.defaultValue - to return if this isSuccess() is falseResult if the isSuccess() is true else
return the default value provided.public abstract <T> T fold(java.util.function.Function<NonEmptyList<E>,T> f, java.util.function.Function<A,T> s)
T - The target return typef - a function to apply to the list of errors for failure, if anys - a function to apply to successfully updated aggregate valuepublic Optional<NonEmptyList<E>> failureReasons()
public <T> Result<E,T> map(java.util.function.Function<A,T> mapper)
Result with the
output value the result of that function.T - The new component typemapper - A functionResult<E, T>NullPointerException - if mapper is nullpublic <F> Result<F,A> errorMap(java.util.function.Function<E,F> errorMapper)
ResultF - The new component typeerrorMapper - The error mapping functionResult<E, T>NullPointerException - if mapper is nullpublic <T> Result<E,T> flatMap(java.util.function.Function<A,Result<E,T>> mapper)
Result with the
extracted reason extracted from the functions returned Result<E, T>T - The new component typemapper - A mapperNullPointerException - if mapper is nullpublic void ifSuccessful(java.util.function.Consumer<A> consumer)
consumer - The consumer to invokeCopyright © 2019. All rights reserved.