Package org.storynode.pigeon.result
Class Err<T,E>
java.lang.Object
org.storynode.pigeon.result.Result<T,E>
org.storynode.pigeon.result.Err<T,E>
- All Implemented Interfaces:
Wrapped<T>
Result variant for errors.- Author:
- Andrea Coronese
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturnsresif the result isOk, otherwise returns the Err value ofthis.LikeResult.and(Result)but lazily evaluated.LikeOption.map(Function)but does not re-wrap the result of the provided mapping function to aResultifOkOrElse(Consumer<T> whenOk, @NotNull Consumer<E> whenError) ExecuteswhenOkif this contains a value,whenErrorotherwise.booleanisOk()Whether thisResultis ok, meaning it contains a value and not an errorMaps aResult<T, E>toResult<U, E>by applying a function to a contained value, leaving a result that contains an error untouched.Maps aResult<T, E>toResult<T, U>by applying a function to a contained error, leaving a result that contains a value untouched.Unwraps the contained value, or returns a default one if this contains an errorUnwraps the contained value, or returns a default one if this contains an errorunwrap()Unwraps and return the inner value, if present.Unwraps and return the inner error, if present.
-
Constructor Details
-
Err
A variant ofResultthat indicates an error value- Parameters:
error- The value for the 'error' result
-
-
Method Details
-
isOk
public boolean isOk()Whether thisResultis ok, meaning it contains a value and not an error -
unwrap
Unwraps and return the inner value, if present. Throws an error if this result contains an error. -
unwrapError
Unwraps and return the inner error, if present. Throws an error if this result contains a value.- Specified by:
unwrapErrorin classResult<T,E> - Returns:
- The inner error
-
orElseGet
Unwraps the contained value, or returns a default one if this contains an error -
map
Maps aResult<T, E>toResult<U, E>by applying a function to a contained value, leaving a result that contains an error untouched. This can be used to compose the result of two functions.Example
Result.ok(2).map(Math:sqrt) // Gets the square root of two as a Result -
flatMap
LikeOption.map(Function)but does not re-wrap the result of the provided mapping function to aResult -
mapError
Maps aResult<T, E>toResult<T, U>by applying a function to a contained error, leaving a result that contains a value untouched. This can be used to compose the result of two functions -
ifOkOrElse
ExecuteswhenOkif this contains a value,whenErrorotherwise.- Specified by:
ifOkOrElsein classResult<T,E> - Parameters:
whenOk- The function to execute when this contains a valuewhenError- The function to execute when this contains an error- Returns:
- this instance (for chaining)
-
orElse
Unwraps the contained value, or returns a default one if this contains an error -
and
Returnsresif the result isOk, otherwise returns the Err value ofthis.
Arguments passed toandare eagerly evaluated; if you are passing the result of a function call, it is recommended to useResult.andThen(Function), which is lazily evaluated. -
andThen
LikeResult.and(Result)but lazily evaluated. The function is supplied the current value of the result if it'sOk
-