Skip to content

chain

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

Defined in: Core/Option.ts:147

Chains Option computations. If the first is Some, passes the value to f. If the first is None, propagates None.

A

B

(a) => Option<B>

(data): Option<B>

Option<A>

Option<B>

const parseNumber = (s: string): Option<number> => {
  const n = parseInt(s, 10);
  return isNaN(n) ? Option.none() : Option.of(n);
};

pipe(Option.of("42"), Option.chain(parseNumber)); // Some(42)
pipe(Option.of("abc"), Option.chain(parseNumber)); // None