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:
SafelyWrapped<T>,Wrapped<T>
Result variant for errors.- Author:
- Andrea Coronese
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionLikeOption.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 errorThe non-throwing variant ofWrapped.unwrap().The non-throwing variant ofResult.unwrapError().unwrap()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. If you need a non throwing version of this method useResult.tryUnwrap() -
unwrapError
Unwraps and return the inner error, if present. Throws an error if this result contains a value. If you need a non throwing version of this method use [#tryUnwrapError()]- 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 -
tryUnwrap
The non-throwing variant ofWrapped.unwrap(). This is guaranteed to never throw and to always return a non-null value.The non-throwing variant of
Wrapped.unwrap(). This is guaranteed to never throw and to always return a non-null value. -
tryUnwrapError
The non-throwing variant ofResult.unwrapError(). This is guaranteed to never throw and to always return a non-null value.- Specified by:
tryUnwrapErrorin classResult<T,E> - Returns:
- An
Optioncontaining the error, or empty if there is none
-
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)
-