andThen

inline fun <In : Any, Out : Any, Error : Any> Outcome<In, Error>.andThen(catch: (throwable: Throwable) -> Outcome<Out, Error> = ::rethrow, success: RaiseScope<Error>.(In) -> Out): Outcome<Out, Error>

Transforms the encapsulated value if this instance represents success.

If success throws an exception, it will be re-encapsulated or re-thrown by outcomeOf. If no exception occurs, or Outcome is failure, the original Outcome is returned unaffected.

outcomeOf { 4 }
.andThen { it * 2 } // Outcome.success(8)
.andThen { check(false) { it } } // Outcome.failure(IllegalStateException("4"))
.andThen { 16 } // Remains Outcome.failure(IllegalStateException("4"))

This is the outcomeOf alternative to Outcome.map.

See also