arrow.meta.prelude.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of arrow-meta Show documentation
Show all versions of arrow-meta Show documentation
Functional companion to Kotlin's Standard Library
/**
* This file will be removed in the next release when arrow `shadow` is published
* and available so we can build Arrow with the previous uber jar of Arrow
*/
package arrow.meta
sealed class Either {
data class Left (val a: A) : Either()
data class Right (val b: B) : Either()
fun map(f: (B) -> C): Either =
flatMap { Right(f(it)) }
inline fun fold(ifLeft: (A) -> C, ifRight: (B) -> C): C = when (this) {
is Right -> ifRight(b)
is Left -> ifLeft(a)
}
}
inline fun Either.flatMap(f: (B) -> Either): Either =
when (this) {
is Either.Right -> f(this.b)
is Either.Left -> this
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy