andThen

inline fun <In, Out> KotlinResult<In>.andThen(onSuccess: (In) -> Out): KotlinResult<Out>

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 } // Remains KotlinResult.failure(IllegalStateException("4"))

See also