validate

inline fun <E, T> MultiErrorKResult<E, T>.validate(failureValue: E, expectationFn: (success: T) -> Boolean): MultiErrorKResult<E, T>(source)

Validates a Success or a FailureWithValue against a predicate (expectationFn] and applies failureValue if not fulfilled

This will return a FailureWithValue in case of an unmatched predicate, so multiple validation failures can be tracked without early termination. If you prefer early termination on the first error, see KResult.filter instead.

Heads up: Be careful with combining validate and flatMap. See documentation of MultiErrorKResult for details

Since

0.2.0

See also

for examples and details