andIf

inline fun <T> KotlinResult<T>.andIf(predicate: (T) -> Boolean, onSuccess: (T) -> T): KotlinResult<T>

If the predicate is true, transforms value inside a resultOf scope.

resultOf { 4 }.andIf({ it 0 }) { it * 2 } // KotlinResult.success(8)
resultOf { 4 }.andIf({ it < 0 }) { it * 2 } // KotlinResult.success(4)

See also