All Downloads are FREE. Search and download functionalities are using the official Maven repository.

arrow.meta.prelude.kt Maven / Gradle / Ivy

There is a newer version: 1.6.3-alpha.2
Show newest version
/**
 * 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