Skip to content

These

These<A, B> = TheseFirst<A> | TheseSecond<B> | TheseBoth<A, B>

Defined in: Core/These.ts:26

These<A, B> is an inclusive-OR type: it holds a first value (A), a second value (B), or both simultaneously. Neither side carries a success/failure connotation — it is a neutral pair where any combination is valid.

  • First(a) — only a first value
  • Second(b) — only a second value
  • Both(a, b) — first and second values simultaneously

A common use: lenient parsers or processors that carry a diagnostic note alongside a result, without losing either piece of information.

A

B

const parse = (s: string): These<number, string> => {
  const trimmed = s.trim();
  const n = parseFloat(trimmed);
  if (isNaN(n)) return These.second("Not a number");
  if (s !== trimmed) return These.both(n, "Leading/trailing whitespace trimmed");
  return These.first(n);
};