throwIf

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

Throws if this is a Failure and predicate returns true 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 true 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 true.

If the Error is null and predicate returns true.

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