Interface Result.Binder<E>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
The unwrapping handle passed to
Result.binding(Function).
Calling on(Result) inside a binding block either returns the success
value or aborts the whole block at the first Result.Err encountered.
The error type is consumed covariantly: a block typed Binder<BankError>
accepts steps returning Result<NoSuchAccount, …>,
Result<WrongPin, …>, and so on, where each subtype implements
BankError. No per-step mapErr is needed; the binding block unifies
the subtypes into the block's E automatically. See ADR-11.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidAssert a condition with no value to bind: a guard, a permission check, an invariant.<T> TUnwrap aResultinside abindingblock: returns the value ifResult.Ok, otherwise short-circuits the enclosing block, which then evaluates to thatResult.Err.default <T> T
-
Method Details
-
on
Unwrap aResultinside abindingblock: returns the value ifResult.Ok, otherwise short-circuits the enclosing block, which then evaluates to thatResult.Err. Only legal while the surroundingbindingcall is on the stack.The error is consumed covariantly (
? extends E), so steps that return a subtype of the block's error are accepted withoutmapErr. -
on
Bind anOptionalinside abindingblock: a present value is returned, an emptyOptionalshort-circuits the block withifEmpty.get(). LetsOptional- andResult-returning calls be sequenced together without bridging each one by hand.var candidates = bind.on(NonEmptyList.fromList(xs), AppError.NoCandidates::new); -
ensure
-