mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-16 05:00:59 +08:00
Represent ordinary JavaScript arrays with hole, value, and explicit-undefined states; add sparse side storage and carry missing values through the frontend, native backends, runtime, and Node-facing consumers.
15 lines
641 B
TypeScript
15 lines
641 B
TypeScript
// Generic callback values remain generic until each HOF call supplies a
|
|
// concrete signature. The optional-array prepass must not ask the generic
|
|
// parameter for a monomorphic ABI too early.
|
|
const identity = <T>(value: T): T => value;
|
|
const pair = <A, B>(left: A, right: B): string => `${left}|${right}`;
|
|
const numberIdentity = identity<number | undefined>;
|
|
|
|
console.log([1, 2, 3].map(numberIdentity).join("+"));
|
|
console.log([1, 2, 3].filter((value) => value > 1).join(","));
|
|
console.log([1, 2, 3].reduce((sum, value) => sum + value, 0));
|
|
console.log(pair(7, "seven"));
|
|
|
|
const f: (value: number) => number = identity;
|
|
console.log(f(41));
|