Interface Result.Binder<E>

Enclosing interface:
Result<E,T>
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public static interface Result.Binder<E>
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.

  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    ensure(boolean condition, Supplier<? extends E> error)
    Assert a condition with no value to bind: a guard, a permission check, an invariant.
    <T> T
    on(Result<E,T> result)
    Unwrap a Result inside a binding block: returns the value if Result.Ok, otherwise short-circuits the enclosing block, which then evaluates to that Result.Err.
    default <T> T
    on(Optional<? extends T> maybe, Supplier<? extends E> ifEmpty)
    Bind an Optional inside a binding block: a present value is returned, an empty Optional short-circuits the block with ifEmpty.get().
  • Method Details

    • on

      <T> T on(Result<E,T> result)
      Unwrap a Result inside a binding block: returns the value if Result.Ok, otherwise short-circuits the enclosing block, which then evaluates to that Result.Err. Only legal while the surrounding binding call is on the stack.
    • on

      default <T> T on(Optional<? extends T> maybe, Supplier<? extends E> ifEmpty)
      Bind an Optional inside a binding block: a present value is returned, an empty Optional short-circuits the block with ifEmpty.get(). Lets Optional- and Result-returning calls be sequenced together without bridging each one by hand.
      var candidates = bind.on(NonEmptyList.fromList(xs), AppError.NoCandidates::new);
      
    • ensure

      default void ensure(boolean condition, Supplier<? extends E> error)
      Assert a condition with no value to bind: a guard, a permission check, an invariant. false short-circuits the enclosing block with the supplied error, exactly like binding an Err; true is a no-op.