R
- The type of the wrapped result.public class DataResult<R> extends Object
Modifier and Type | Class and Description |
---|---|
static class |
DataResult.Instance
The applicative functor type instance for the type constructor
DataResult . |
static class |
DataResult.PartialResult<R>
A container for a partial result in an error
DataResult . |
Modifier and Type | Method and Description |
---|---|
DataResult<R> |
addLifecycle(Lifecycle lifecycle)
Returns a
DataResult with the same value as this result, but with the provided lifecycle added to
this result's lifecycle. |
<R2> DataResult<R2> |
ap(DataResult<(R) -> R2> functionResult)
Applies a function which is itself wrapped in a
DataResult to the result or partial result. |
<R2,S> DataResult<S> |
apply2((R,R2) -> S function,
DataResult<R2> second)
Combines this result with another result using the given function.
|
<R2,S> DataResult<S> |
apply2stable((R,R2) -> S function,
DataResult<R2> second)
Combines this result with another result using the given function, under the "stable" lifecycle.
|
<R2,R3,S> DataResult<S> |
apply3((R,R2,R3) -> S function,
DataResult<R2> second,
DataResult<R3> third)
Combines this result with two other results using the given function.
|
boolean |
equals(Object o) |
Optional<DataResult.PartialResult<R>> |
error()
Returns the error
DataResult.PartialResult , if one is present. |
static <R> DataResult<R> |
error(String message)
Creates an error
DataResult with the given message and no partial result. |
static <R> DataResult<R> |
error(String message,
Lifecycle lifecycle)
Creates an error
DataResult with the given message and lifecycle. |
static <R> DataResult<R> |
error(String message,
R partialResult)
Creates an error
DataResult with the given message and partial result value. |
static <R> DataResult<R> |
error(String message,
R partialResult,
Lifecycle lifecycle)
Creates an error
DataResult with the given message, partial result value, and lifecycle. |
<R2> DataResult<R2> |
flatMap((? super R) -> ? extends DataResult<R2> function)
Applies the function to either full or partial result, in case of partial concatenates errors.
|
(R|DataResult.PartialResult<R>) |
get()
Returns the wrapped
Either . |
R |
getOrThrow(boolean allowPartial,
(String) -> void onError)
Unsafely gets the result stored in this
DataResult . |
int |
hashCode() |
static instance DataResult<_> |
instance()
Returns the applicative type instance for the type
DataResult . |
Lifecycle |
lifecycle()
Returns the lifecycle used in this
DataResult . |
<T> DataResult<T> |
map((? super R) -> ? extends T function)
Applies a function to the result or partial result.
|
DataResult<R> |
mapError((String) -> String function)
Applies the given function to the error message contained in this result.
|
static <K,V> (K) -> DataResult<V> |
partialGet((K) -> V partialGet,
by-name String errorPrefix)
Converts a partial function into a function that produces a
DataResult . |
DataResult<R> |
promotePartial((String) -> void onError)
Promotes an error with a partial result to a success.
|
Optional<R> |
result()
Returns the successful result, if one is present.
|
Optional<R> |
resultOrPartial((String) -> void onError)
Returns any result, if one is present.
|
DataResult<R> |
setLifecycle(Lifecycle lifecycle)
Returns a
DataResult with the same value as this result, but with the provided lifecycle. |
DataResult<R> |
setPartial(R partial)
If this result is an error, replaces any partial result with the given partial result.
|
DataResult<R> |
setPartial(by-name R partial)
If this result is an error, replaces any partial result with the supplied partial result.
|
static <R> DataResult<R> |
success(R result)
Creates a successful
DataResult with the given result value. |
static <R> DataResult<R> |
success(R result,
Lifecycle experimental)
Creates a successful
DataResult with the given result value and lifecycle. |
String |
toString()
Returns a
String describing this DataResult . |
public static <R> DataResult<R> success(R result)
DataResult
with the given result value. The lifecycle of the result
is experimental.R
- The type of the result value.result
- The result value.DataResult
.success(Object, Lifecycle)
public static <R> DataResult<R> error(String message, R partialResult)
DataResult
with the given message and partial result value.R
- The type of the result value.message
- The error message.partialResult
- The partial or fallback result value.DataResult
.error(String, Object, Lifecycle)
public static <R> DataResult<R> error(String message)
DataResult
with the given message and no partial result.R
- The expected type of the result.message
- The error message.DataResult
.error(String, Object)
public static <R> DataResult<R> success(R result, Lifecycle experimental)
DataResult
with the given result value and lifecycle.R
- The type of the result value.result
- The result value.experimental
- The lifecycle to use.DataResult
.success(Object, Lifecycle)
public static <R> DataResult<R> error(String message, R partialResult, Lifecycle lifecycle)
DataResult
with the given message, partial result value, and lifecycle.R
- The type of the result value.message
- The error message.partialResult
- The partial or fallback result value.lifecycle
- The lifecycle to use.DataResult
.public static <R> DataResult<R> error(String message, Lifecycle lifecycle)
DataResult
with the given message and lifecycle.R
- The expected type of the result.message
- The error message.lifecycle
- The lifecycle to use.DataResult
.error(String)
public static <K,V> (K) -> DataResult<V> partialGet((K) -> V partialGet, by-name String errorPrefix)
DataResult
. If the partial function
returns null
, then the returned function returns an error DataResult
, otherwise a successful
DataResult
.K
- The argument type of the partial function.V
- The result type of the partial function.partialGet
- The partial function.errorPrefix
- The error string to use if partialGet
returns null
.DataResult
.Optional
public (R|DataResult.PartialResult<R>) get()
Either
.public Optional<R> result()
error()
public Lifecycle lifecycle()
DataResult
.public Optional<R> resultOrPartial((String) -> void onError)
onError
- A callback to run on error. It receives the error message.public R getOrThrow(boolean allowPartial, (String) -> void onError)
DataResult
.allowPartial
- Whether to return the partial result if this is an error.onError
- A callback to run on error. It receives the error message.RuntimeException
- If this DataResult
does not contain a result value.public Optional<DataResult.PartialResult<R>> error()
DataResult.PartialResult
, if one is present.result()
public <T> DataResult<T> map((? super R) -> ? extends T function)
DataResult
.T
- The new result type.function
- The conversion function.flatMap(Function)
,
ap(DataResult)
public DataResult<R> promotePartial((String) -> void onError)
onError
- A callback to run on error. It is passed the error string.public <R2> DataResult<R2> flatMap((? super R) -> ? extends DataResult<R2> function)
DataResult
.R2
- The new result type.function
- The partial conversion function.map(Function)
public <R2> DataResult<R2> ap(DataResult<(R) -> R2> functionResult)
DataResult
to the result or partial result.
If either this
or functionResult
are errors, then the return value is also an error.
Also, if either this
or functionResult
does not contain a result, then the
return value also does not contain a result.
DataResult
.R2
- The new result type.functionResult
- The function to potentially apply.functionResult
applies to this
.map(Function)
,
Applicative
,
Functors, Applicatives, and Monadspublic <R2,S> DataResult<S> apply2((R,R2) -> S function, DataResult<R2> second)
map(Function)
.R2
- The type of the second result value.S
- The type of the output result value.function
- The function to apply to the wrapped values of this and the given result.second
- The second DataResult
value.DataResult
wrapping the application of the function
to the provided results.map(Function)
public <R2,S> DataResult<S> apply2stable((R,R2) -> S function, DataResult<R2> second)
This method is equivalent to apply2(BiFunction, DataResult)
, except that the stable lifecycle
is always used.
R2
- The type of the second result value.S
- The type of the output result value.function
- The function to apply to the wrapped values of this and the given result.second
- The second DataResult
value.DataResult
wrapping the application of the function
to the provided results.apply2(BiFunction, DataResult)
,
map(Function)
public <R2,R3,S> DataResult<S> apply3((R,R2,R3) -> S function, DataResult<R2> second, DataResult<R3> third)
map(Function)
.R2
- The type of the second result value.R3
- The type of the third result value.S
- The type of the output result value.function
- The function to apply to the wrapped values of this and the given results.second
- The second DataResult
value.third
- The third DataResult
value.DataResult
wrapping the application of the function
to the provided results.map(Function)
public DataResult<R> setPartial(by-name R partial)
partial
- A Supplier
of partial results.DataResult
equivalent to this
with the partial result set appropriately.public DataResult<R> setPartial(R partial)
partial
- A partial result.DataResult
equivalent to this
with the partial result set appropriately.public DataResult<R> mapError((String) -> String function)
function
- The function to apply.DataResult
equivalent to this
, but with any error message replaced.public DataResult<R> setLifecycle(Lifecycle lifecycle)
DataResult
with the same value as this result, but with the provided lifecycle.public DataResult<R> addLifecycle(Lifecycle lifecycle)
DataResult
with the same value as this result, but with the provided lifecycle added to
this result's lifecycle.Lifecycle.add(Lifecycle)
public static instance DataResult<_> instance()
DataResult
.DataResult.Instance
public String toString()
String
describing this DataResult
.