throwUnless

inline fun <Ok, Error> Outcome<Ok, Error>.throwUnless(fallbackMessage: (Error) -> String = { "Outcome was Failure and throwUnless predicate was false: $it" }, predicate: (Error) -> Boolean): Outcome<Ok, Error>

Throws if this is a Failure and predicate returns false for the error. Returns the original Outcome unchanged otherwise.

Parameters

fallbackMessage

Produces the exception message from the error value. Only used when Error is not already a Throwable or nz.adjmunro.outcome.throwable.ThrowableWrapper — in those cases the existing exception is thrown as-is and this parameter is ignored.

predicate

Returns false if the error should be thrown.

See also

Throws

The Error itself if it is a Throwable, or its cause if it is a ThrowableWrapper, when predicate returns false.

If the Error is null and predicate returns false.

If the Error is any other non-throwable type and predicate returns false.