andThen

inline fun <I, O> KotlinResult<I>.andThen(onSuccess: (I) -> O): KotlinResult<O>

Transforms value inside a resultOf scope.

This is the resultOf alternative to Result.mapCatching.

resultOf { 4 }
.andThen { it * 2 } // KotlinResult.success(8)
.andThen { check(false) { it } } // KotlinResult.failure(IllegalStateException("4"))
.andThen { 16 } // RemainsKotlinResult.failure(IllegalStateException("4"))

See also