Skip to content

stopcock

Pipe-based FP for TypeScript. Fuses array operations into single loops.
import { pipe, A } from '@stopcock/fp'
const topActive = pipe(
players,
A.filter(p => p.active && p.score > 0),
A.map(p => ({ name: p.name, score: p.score })),
A.take(10),
)

pipe spots that filter, map, and take can all run in one loop, so it fuses them. take(10) bails out after 10 hits. On a million-element array, that means touching a few dozen items instead of three full passes.

9xfilter→map→take(10) on 100K elements

import { pipe, O, R } from '@stopcock/fp'
const port = pipe(
O.fromNullable(process.env.PORT),
O.map(s => parseInt(s, 10)),
O.filter(n => n > 0 && n < 65536),
O.getOrElse(() => 3000),
)
const parsed = pipe(
R.tryCatch(() => JSON.parse(raw)),
R.map(obj => obj.data),
R.getOrElse(() => []),
)

Option for values that might not exist, Result for things that can fail. Both use numeric _tag instead of strings, so V8 can branch on them fast.



Standalone packages. They all work with pipe and with each other.

Terminal window
bun add @stopcock/fp