result.andThen
The result of a fallible next step on a success, with diagnostics accumulated; a failure short-circuits.
Usage
Result.andThen<T, U>(r: Result<T>, f: (value: T) => Result<U>): Result<U>Parameters
rResult<T>The result to read.
f(value: T) => Result<U>The next step, returning a
Result.
Returns
A failure of r unchanged (f is not called). Otherwise f’s result with r’s diagnostics added: before the step’s on success, after them on failure, so a failure’s first diagnostic is still the step’s error.
Example
Result.andThen(Result.ok(4), (n) => (n > 0 ? Result.ok(Math.sqrt(n)) : Result.fail('GEOMETRY_INPUT_INVALID', 'negative'))).value // → 2