Record Class Result.Err<Value,Error>
java.lang.Object
java.lang.Record
dmx.fun.Result.Err<Value,Error>
- Type Parameters:
Value- the type of the value contained in a successful result, unused hereError- the type of the error contained in the erroneous result- Record Components:
error- the non-null error value that represents the erroneous result; passingnullthrowsNullPointerException
- All Implemented Interfaces:
Result<Value,Error>
public static record Result.Err<Value,Error> (Error error)
extends Record
implements Result<Value,Error>
Represents an erroneous result containing an error of type
Error.
This record implements the Result interface and represents the "Err" variant
of a result. It encapsulates an error value that indicates a failed computation or action.
-
Nested Class Summary
Nested classes/interfaces inherited from interface Result
Result.Err<Value,Error>, Result.Ok<Value, Error>, Result.Partition<V, E> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.error()Returns the value of theerrorrecord component.default <R> RFolds this container to a single value by applying the appropriate function.default ValueReturns the success value if present, orfallbackotherwise.default ValuegetOrElseGet(Supplier<Value> supplier) Returns the success value if present, or the value produced bysupplierotherwise.default ValueReturns the success value if present, ornullotherwise.default ValuegetOrThrow(Function<Error, ? extends RuntimeException> exMapper) Returns the success value if present, or throws an exception mapped from the error.final inthashCode()Returns a hash code value for this object.default voidExecutes one of the two consumers based on the active variant.stream()Returns a single-element stream of the success value, or an empty stream on error.toOption()Converts this container to anOption.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Err
Compact canonical constructor — validates thaterroris non-null.- Throws:
NullPointerException- iferrorisnull
-
-
Method Details
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
error
-
getOrElse
Returns the success value if present, orfallbackotherwise.- Parameters:
fallback- the non-null fallback value- Returns:
- the success value, or
fallbackif this is the error variant - Throws:
NullPointerException- iffallbackisnull
-
getOrElseGet
Returns the success value if present, or the value produced bysupplierotherwise.- Parameters:
supplier- supplier of the fallback value; must not returnnull- Returns:
- the success value, or the value produced by
supplier - Throws:
NullPointerException- ifsupplierisnullor returnsnull
-
getOrNull
Returns the success value if present, ornullotherwise.- Returns:
- the success value or
null
-
getOrThrow
Returns the success value if present, or throws an exception mapped from the error.- Parameters:
exMapper- maps the error to aRuntimeException; must not returnnull- Returns:
- the success value
- Throws:
NullPointerException- ifexMapperisnullor returnsnullRuntimeException- the exception produced byexMapperon the error variant
-
stream
-
fold
Folds this container to a single value by applying the appropriate function.- Type Parameters:
R- the result type- Parameters:
onSuccess- applied to the success value; must not returnnullonError- applied to the error value; must not returnnull- Returns:
- the result of the applied function
- Throws:
NullPointerException- if either function isnullor returnsnull
-
match
Executes one of the two consumers based on the active variant.- Parameters:
onSuccess- called with the success valueonError- called with the error value- Throws:
NullPointerException- if either consumer isnull
-
toOption
Converts this container to anOption. The success variant maps toOption.Some; the error variant maps toOption.none().- Returns:
- an
Optioncontaining the success value, or empty
-