fold

inline fun <C> fold(ifLeft: (A) -> C, ifRight: (B) -> C): C

Applies ifLeft if this is a Left or ifRight if this is a Right.

Example:

import arrow.core.*

fun main() {
fun possiblyFailingOperation(): Either.Right<Int> =
Either.Right(1)
//sampleStart
val result: Either<Exception, Int> = possiblyFailingOperation()
result.fold(
{ println("operation failed with $it") },
{ println("operation succeeded with $it") }
)
//sampleEnd
}

Return

the results of applying the function

Parameters

ifLeft

the function to apply if this is a Left

ifRight

the function to apply if this is a Right