commonMain.outcome.Accessors.kt Maven / Gradle / Ivy
package opensavvy.state.outcome
import opensavvy.state.outcome.Outcome.Success
// region Get or null
/**
* Returns [Success.value], or `null` if this outcome is not successful.
*/
val Outcome<*, Value>.valueOrNull: Value?
get() = (this as? Success)?.value
/**
* Returns [Failure.failure][Outcome.Failure.failure], or `null` if this outcome is not a failure.
*/
val Outcome.failureOrNull: Failure?
get() = (this as? Outcome.Failure)?.failure
// endregion
// region Safe get via Nothing
/**
* Returns [Success.value].
*/
val Outcome.value: Value
// This cast is safe, because a Failure of Nothing is impossible
get() = (this as Success).value
/**
* Returns [Failure.failure][Outcome.Failure.failure].
*/
val Outcome.failure: Failure
// This cast is safe, because a Success of Nothing is impossible
get() = (this as Outcome.Failure).failure
// endregion