app.cash.quiver.Outcome.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lib Show documentation
Show all versions of lib Show documentation
Quiver library providing extension methods and type aliases to improve Arrow
The newest version!
@file:Suppress("DEPRECATION")
package app.cash.quiver
import app.cash.quiver.extensions.OutcomeOf
import arrow.core.Either
import arrow.core.Either.Left
import arrow.core.Either.Right
import arrow.core.None
import arrow.core.Option
import arrow.core.Some
import arrow.core.Validated
import arrow.core.flatMap
import arrow.core.getOrElse
import arrow.core.identity
import arrow.core.left
import arrow.core.right
import arrow.core.some
import arrow.core.valid
import app.cash.quiver.extensions.orThrow
import app.cash.quiver.extensions.toResult
import app.cash.quiver.raise.OutcomeRaise
import app.cash.quiver.raise.outcome
import arrow.core.raise.catch
import kotlin.experimental.ExperimentalTypeInference
/**
* `Outcome` is a type that represents three possible states a result can be in: Present, Absent or Failure. Under the
* hood it wraps the type `Either>` and supports the common functions that Eithers and Options support such
* as [`map`](app.cash.quiver.Outcome.map), [`flatMap`](app.cash.quiver.Outcome.flatMap) and
* [`zip`](app.cash.quiver.Outcome.zip).
*
* There are three primary constructors:
*
* ```kotlin
* data class Present(val value: A) : Outcome
* data class Failure(val error: E) : Outcome
* object Absent : Outcome
* ```
*
* or you can use the extension methods thusly:
*
* ```kotlin
* A.present()
* E.failure()
* ```
*
* You can also easily convert an `Either