Skip to content

chain

chain<E, A, B>(f): (data) => These<E, B>

Defined in: Core/These.ts:154

Chains These computations by passing the success value to f.

  • Err propagates unchanged.
  • Ok(a) applies f(a) directly.
  • Both(e, a): applies f(a); if the result is Ok(b), returns Both(e, b) to preserve the warning. Otherwise returns f(a) as-is.

E

A

B

(a) => These<E, B>

(data): These<E, B>

These<E, A>

These<E, B>

const double = (n: number): These<string, number> => These.ok(n * 2);

pipe(These.ok(5), These.chain(double));           // Ok(10)
pipe(These.both("warn", 5), These.chain(double)); // Both("warn", 10)
pipe(These.err("err"), These.chain(double));      // Err("err")