fold

inline fun <R> fold(ifFailure: (failure: E) -> R, ifSuccess: (success: T) -> R): R(source)

Transforms a KResult into a value of R.

import io.kresult.core.KResult
import io.kotest.matchers.shouldBe
import kotlin.test.fail

fun test() {
KResult.Success(1)
.fold(
{ fail("Cannot be left") },
{ it + 1 }
) shouldBe 2
}

Return

the transformed value R by applying ifFailure or ifSuccess.

Parameters

ifFailure

transform the KResult.Failure type E to R.

ifSuccess

transform the KResult.Success type T to R.