commonMain.outcome.Conditional.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of state-jvm Show documentation
Show all versions of state-jvm Show documentation
Progress-aware failure states
The newest version!
package opensavvy.state.outcome
import opensavvy.state.outcome.Outcome.Success
/**
* Executes [block] if this outcome is [successful][Success].
*
* Otherwise, does nothing.
*/
inline fun Outcome<*, Value>.onSuccess(block: (Value) -> Unit) {
if (this is Success)
block(this.value)
}
/**
* Executes [block] if this outcome is a [failure][Failure].
*
* Otherwise, does nothing.
*/
inline fun Outcome.onFailure(block: (Failure) -> Unit) {
if (this is Outcome.Failure)
block(this.failure)
}