Modifier and Type | Method and Description |
---|---|
static <S,F> Result<S,F> |
ofSupplier(Supplier<Result<S,F>> supplier)
Creates a new lazy result based on the given result supplier.
|
public static <S,F> Result<S,F> ofSupplier(Supplier<Result<S,F>> supplier)
S
- the success type of the resultF
- the failure type of the resultsupplier
- the function that supplies the actual resultNullPointerException
- if supplier
is null
LazyConsumer.of(Consumer)
supplier
is not allowed to return null
or throw any exceptions. If it does, then the
lazy result will relay the thrown exception (or NullPointerException
) to its caller when/if it needs to be evaluated. If the lazy result needs to be
evaluated again, it will throw NoSuchElementException
(instead of trying to invoke supplier
again). This ensures that supplier
will be invoked at most once.