Muhammad Talha
04/28/2022, 7:22 AMOutcome.Success
class with a value. However is it possible to use it without a value? There are some cases where I don’t want to pass a value in. I’m not quite sure what the definition would be for me not to pass a value in while not making value optional. Thanks!
sealed class Outcome<out T: Any> {
class Success<out T: Any>(val value: T) : Outcome<T>()
class Error(val msg: String, val exp: Exception? = null) : Outcome<Nothing>()
}
simon.vergauwen
04/28/2022, 7:29 AMUnit
which means Success
without a meaningful value.
In functional programming Either<Error, Unit>
is typically used to signal that something can either fail with Error
or succeed with no meaning value.Either
for example can be found in Arrow Core. https://arrow-kt.io/docs/core/ and it offers nice DSLs for not requiring flatMap
& map
etc.Muhammad Talha
04/28/2022, 7:51 AMsimon.vergauwen
04/28/2022, 7:57 AM