
Alternative to the Result type, enabling typed error handling. Supports operations like `getOrElse`, `map`, and `flatMap` for enhanced error management and control flow.
Outcome is an alternative to Kotlin's Result type that lets you add types to your errors.
fun main() {
val coinFace = flipCoin().getOrElse {
when (error) {
FlipCoinError.CoinBroke -> changeGame()
FlipCoinError.CoinExploded -> cleanup()
}
return
}
println("Flipped ${coinFace.name}")
}
fun flipCoin(): Outcome<CoinFace, FlipCoinError>
enum class FlipCoinError {
CoinBroke,
CoinExploded,
}See Sample.kt for a more concrete example.
Please refer to Map.kt and FlatMap.kt to see the available functions.
Outcome is an alternative to Kotlin's Result type that lets you add types to your errors.
fun main() {
val coinFace = flipCoin().getOrElse {
when (error) {
FlipCoinError.CoinBroke -> changeGame()
FlipCoinError.CoinExploded -> cleanup()
}
return
}
println("Flipped ${coinFace.name}")
}
fun flipCoin(): Outcome<CoinFace, FlipCoinError>
enum class FlipCoinError {
CoinBroke,
CoinExploded,
}See Sample.kt for a more concrete example.
Please refer to Map.kt and FlatMap.kt to see the available functions.