diff --git a/src/main/kotlin/com/github/michaelbull/result/Map.kt b/src/main/kotlin/com/github/michaelbull/result/Map.kt index 61c4819..fcf419e 100644 --- a/src/main/kotlin/com/github/michaelbull/result/Map.kt +++ b/src/main/kotlin/com/github/michaelbull/result/Map.kt @@ -172,6 +172,11 @@ inline infix fun Result.flatMap(transform: (V) -> Result): * and satisfies the given [predicate], otherwise this [Result]. */ inline fun Result.toErrorIf(predicate: (V) -> Boolean, transform: (V) -> E): Result { + contract { + callsInPlace(predicate, InvocationKind.AT_MOST_ONCE) + callsInPlace(transform, InvocationKind.AT_MOST_ONCE) + } + return when (this) { is Ok -> if (predicate(value)) { Err(transform(value))