-
Notifications
You must be signed in to change notification settings - Fork 78
Scala
Michael Bull edited this page Jan 10, 2018
·
13 revisions
Mappings from Scala's Either type to kotlin-result.
<V, E, U, F> Result<V, E>.mapEither(success: (V) -> U, failure: (E) -> F): Result<U, F>
Applies success if this is Ok or failure if this is an Err.
val result = possiblyFailingOperation()
logger.info(result.mapEither(
success = { "Operation produced value: ${it.value}" },
failure = { "Operation failed with ${it.reason}" }
))<V, E> Result<V, E>.getOr(default: V): V
Returns the value from this Ok or the given argument if this is an Err.
Ok(12).getOr(17) // 12
Err(12).getOr(17) // 17<V, E, U> Result<V, E>.andThen(transform: (V) -> Result<U, E>): Result<U, E>
The given function is applied if this is Ok.
Ok(12).andThen { "flower" } // Result: Ok("flower")<V, E> Result<V, E>.get(): V?
Returns the value if it exists or null if this is an Err.