and Then
Transforms value inside a resultOf scope.
Success ->wraps&
returns
the result of onSuccess transformation.If onSuccess throws an exception, it will be caught & wrapped by resultOf.
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"))
Content copied to clipboard