and If
Conditionally transforms the encapsulated value if success and predicate returns true. If predicate returns false, the value is left unchanged.
Exceptions from success are caught by result. Do not use in suspend contexts — CancellationException will be caught.
Failures pass through unchanged.
result { 4 }.andIf({ it > 0 }) { it * 2 } // Result.success(8)
result { 4 }.andIf({ it < 0 }) { it * 2 } // Result.success(4)Content copied to clipboard