Class Result<Success,Failure>
java.lang.Object
gov.nasa.jpl.aerie.merlin.framework.Result<Success,Failure>
- Type Parameters:
Success- The type of the success variant of the Result.Failure- The type of the failure variant of the Result.
This class is the equivalent of the type `Result L R = Success L | Failure R` in a language with algebraic data types,
but adapted to the vagaries of the Java platform. The sum alternatives are represented as a closed family of classes
implementing a common interface. Case evaluation is represented by the visitor pattern.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic interfacestatic interfaceResult.VisitorCase<Input,Output, Throws extends Throwable> -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic <Success,Failure>
Result<Success, Failure> failure(Failure value) Factory method for the Right variant.getFailureOrThrow(Function<Success, Throws> factory) getKind()getSuccessOrThrow(Function<Failure, Throws> factory) inthashCode()map(Result.VisitorCase<Success, OutputSuccess, Throws> onSuccess, Result.VisitorCase<Failure, OutputFailure, Throws> onFailure) mapFailure(Result.VisitorCase<Failure, Output, Throws> onFailure) mapSuccess(Result.VisitorCase<Success, Output, Throws> onSuccess) abstract <Output,Throws extends Throwable>
Outputmatch(Result.Visitor<Success, Failure, Output, Throws> visitor) <Output,Throws extends Throwable>
Outputmatch(Result.VisitorCase<Success, Output, Throws> onSuccess, Result.VisitorCase<Failure, Output, Throws> onFailure) Convenience method for matching in a way syntactically similar to switch statements.static <Success,Failure>
Result<Success, Failure> success(Success value) Factory method for the Left variant.toString()
-
Method Details
-
match
public abstract <Output,Throws extends Throwable> Output match(Result.Visitor<Success, Failure, throws ThrowsOutput, Throws> visitor) - Throws:
Throws
-
success
Factory method for the Left variant. -
failure
Factory method for the Right variant. -
match
public <Output,Throws extends Throwable> Output match(Result.VisitorCase<Success, Output, throws ThrowsThrows> onSuccess, Result.VisitorCase<Failure, Output, Throws> onFailure) Convenience method for matching in a way syntactically similar to switch statements.- Throws:
Throws
-
map
public <OutputSuccess,OutputFailure, Result<OutputSuccess,Throws extends Throwable> OutputFailure> map(Result.VisitorCase<Success, OutputSuccess, throws ThrowsThrows> onSuccess, Result.VisitorCase<Failure, OutputFailure, Throws> onFailure) - Throws:
Throws
-
mapSuccess
public <Output,Throws extends Throwable> Result<Output,Failure> mapSuccess(Result.VisitorCase<Success, Output, throws ThrowsThrows> onSuccess) - Throws:
Throws
-
mapFailure
public <Output,Throws extends Throwable> Result<Success,Output> mapFailure(Result.VisitorCase<Failure, Output, throws ThrowsThrows> onFailure) - Throws:
Throws
-
getSuccessOrThrow
public <Throws extends Throwable> Success getSuccessOrThrow(Function<Failure, Throws> factory) throws Throws- Throws:
Throws
-
getFailureOrThrow
public <Throws extends Throwable> Failure getFailureOrThrow(Function<Success, Throws> factory) throws Throws- Throws:
Throws
-
getSuccessOrThrow
-
getFailureOrThrow
-
getKind
-
equals
-
hashCode
public int hashCode() -
toString
-