Skip to content

Pair

Pair<A, B> = readonly [A, B]

Defined in: Core/Pair.ts:23

Pair<A, B> represents a pair of two values that are always both present. It is a typed alias for readonly [A, B].

Use Pair when two values always travel together through a pipeline and you want to transform either or both sides without destructuring.

A

B

import { Pair } from "@nlozgachev/pipelined/core";
import { pipe } from "@nlozgachev/pipelined/composition";

const entry = Pair.from.pair("alice", 42);

pipe(
  entry,
  Pair.mapFirst((name) => name.toUpperCase()),
  Pair.mapSecond((score) => score * 2),
  Pair.fold((name, score) => `${name}: ${score}`),
); // "ALICE: 84"