typestar

Typed zip in TypeScript

Pairs parallel arrays into typed tuples.

function zip<A, B>(left: A[], right: B[]): Array<[A, B]> {
  const length = Math.min(left.length, right.length);
  const out: Array<[A, B]> = [];
  for (let i = 0; i < length; i++) {
    out.push([left[i], right[i]]);
  }
  return out;
}

Keywords and builtins used here

The run, in numbers

Lines
8
Characters to type
223
Tokens
98
Three-star pace
105 tpm

At the three-star pace of 105 tokens a minute, this run takes about 56 seconds.

Type this snippet

Step 8 of 11 in Generic helpers, step 16 of 20 in Generics.

← Previous Next →