Package org.daiitech.naftah.builtin.lang
Class Result.Error<T,E>
java.lang.Object
org.daiitech.naftah.builtin.lang.Result.Error<T,E>
- Type Parameters:
T- the type of the success value (unused in Error, but part of Result)E- the type of the error value
- All Implemented Interfaces:
Result<T,E>
Represents a failed result containing an error value of type
E.-
Nested Class Summary
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionApplies a function that returns anotherResult, effectively flattening the structure.booleanisError()Returnstrueif the result is anError, otherwisefalse.booleanisOk()Returnstrueif the result is anOk, otherwisefalse.Maps the success value to another value using the given function, if present.static <T,E> Result.Error<T, E> of(E error) Creates a newErrorresult with the given error value.toString()unwrap()Returns the contained success value if present, or throws aNaftahBugErrorif this is anError.Returns the contained error value if present, or throws aNaftahBugErrorif this is anOk.Returns the success value if this is anOk, otherwise returns the given default.
-
Field Details
-
error
-
-
Constructor Details
-
Error
-
-
Method Details
-
of
Creates a newErrorresult with the given error value.- Parameters:
error- the error value- Returns:
- a new
Errorinstance
-
isOk
public boolean isOk()Returnstrueif the result is anOk, otherwisefalse. -
isError
public boolean isError()Returnstrueif the result is anError, otherwisefalse. -
unwrap
Returns the contained success value if present, or throws aNaftahBugErrorif this is anError. -
unwrapError
Returns the contained error value if present, or throws aNaftahBugErrorif this is anOk.- Specified by:
unwrapErrorin interfaceResult<T,E> - Returns:
- the error value
-
unwrapOr
Returns the success value if this is anOk, otherwise returns the given default. -
map
Maps the success value to another value using the given function, if present. If this is anError, the error is propagated. -
flatMap
Applies a function that returns anotherResult, effectively flattening the structure. If this is anError, it is propagated unchanged. -
toString
-