Suppose your e-commerce backend hands you a raw array of orders. You need to filter out completed purchases, group them by customer, total up the revenue per person, and return a clear error if the list is empty. In standard TypeScript, a task like that quickly snowballs into intermediate variables, nested calls, and guard checks that bury the actual business logic.
For linear chains, people usually reach for heavyweights like Ramda or fp-ts, paying the price in bundle size or wrapping every value in monads. While browsing Best of JS, I came across fp-pack by superlucky84 (currently on 0.16.0). What caught my eye was its pragmatic bet: zero dependencies, no monad wrappers, strict type inference, and clean early exits on failure.
From nested parentheses to a linear data flow
The first steps of transforming an order array with built-in JavaScript methods look tidy enough, right up until you need to group by customer and the chain breaks:
interface Order {
id: string;
customerId: string;
amount: number;
status: 'pending' | 'completed' | 'cancelled';
}
const orders: Order[] = [
{ id: 'ord-1', customerId: 'cust-a', amount: 1500, status: 'completed' },
{ id: 'ord-2', customerId: 'cust-b', amount: 400, status: 'pending' },
{ id: 'ord-3', customerId: 'cust-a', amount: 2200, status: 'completed' },
{ id: 'ord-4', customerId: 'cust-c', amount: 900, status: 'cancelled' },
];
const completed = orders.filter((order) => order.status === 'completed');
const revenueByCustomer = completed.reduce<Record<string, number>>((acc, order) => {
acc[order.customerId] = (acc[order.customerId] ?? 0) + order.amount;
return acc;
}, {});
There are two headaches here. Every .filter() or .map() allocates a new intermediate array in memory, and any non-standard step like grouping forces you to snap the chain and drop down to a manual reduce.
If you swap array methods for plain functions instead, you end up reading nested calls from the inside out. To turn that processing into a top-down flow, you need a single composition primitive without extra ceremony.
Pipe-first, auto-currying, and 32-step type inference
fp-pack is built on a simple rule: if every multi-argument utility takes its data last and is curried by default, functions snap together left-to-right in a pipeline. The package installs with zero transitive dependencies:
npm install fp-pack
# or
pnpm add fp-pack
The library ships over 96 functions across 10 categories — arrays, objects, strings, math, async, streams, and control flow. ESM, CommonJS, and UMD builds all support tree-shaking, so only the functions you actually import land in your bundle.
Let's rewrite the customer revenue calculation using pipe:
import { pipe, filter, groupBy, mapValues, map, prop, sum } from 'fp-pack';
const revenueByCustomer = pipe(
orders,
filter((order) => order.status === 'completed'),
groupBy((order) => order.customerId),
mapValues((customerOrders) =>
pipe(customerOrders, map(prop('amount')), sum)
)
);
// { 'cust-a': 3700 }
Passing orders as the first argument puts pipe in value-first mode. It executes immediately and anchors TypeScript's generics to Order[], letting the compiler infer every callback type up to 32 steps deep and surface a PipeError diagnostic if two steps don't align.
You don't need noisy arrow-function adapters here: filter and groupBy are already curried and return unary functions ready for pipe. If you want a reusable transformer without immediate execution, pipe also supports functions-first mode — passing only functions — though you'll want to annotate the input type if the first step is polymorphic. For your own helpers with default or rest parameters, there's a curryN wrapper.
Error handling without monads, lazy streams, and trade-offs
In fp-ts, errors live inside Either or Maybe containers: it's like shipping every part down a conveyor belt inside a sealed capsule that you have to crack open and reseal with map or flatMap at every station. fp-pack picks a different model — an emergency relief valve on the pipe. While orders are valid, plain values flow through; when a step fails, it returns a SideEffect.of marker wrapping a deferred function, and pipeSideEffect short-circuits past the remaining stages:
import {
pipeSideEffect, pipe, SideEffect, isSideEffect, runPipeResult,
filter, groupBy, mapValues, map, prop, sum,
} from 'fp-pack';
const calculateRevenue = pipeSideEffect(
(input: Order[]) =>
input.length > 0 ? input : SideEffect.of(() => ({ code: 'EMPTY_ORDERS' as const })),
filter((order) => order.amount > 0 && order.status === 'completed'),
(completed) =>
completed.length > 0
? completed
: SideEffect.of(() => ({ code: 'NO_VALID_COMPLETED' as const })),
groupBy((order) => order.customerId),
mapValues((customerOrders) => pipe(customerOrders, map(prop('amount')), sum))
);
const rawResult = calculateRevenue(orders);
const summary = isSideEffect(rawResult)
? { ok: false as const, error: runPipeResult(rawResult) }
: { ok: true as const, revenueByCustomer: rawResult };
Notice the "contagion" rule: if even one step can return a SideEffect, the outer chain must use pipeSideEffect (or pipeAsyncSideEffect for async flows), while an effect-free inner transform like the one inside mapValues stays a plain pipe.
At the boundary, isSideEffect narrows the type: runPipeResult extracts the exact error union (EMPTY_ORDERS or NO_VALID_COMPLETED), or you get the revenue dictionary. Just don't widen the result manually to SideEffect<any>, or runPipeResult's default type parameter will collapse inference back to any.
For hundreds of thousands of records where allocating intermediate arrays gets expensive, there's a lazy fp-pack/stream module:
import { pipe } from 'fp-pack';
import { filter, map, take, toArray } from 'fp-pack/stream';
const firstFiveLargeOrders = pipe(
filter((order: Order) => order.status === 'completed' && order.amount >= 1000),
map((order) => ({ id: order.id, amount: order.amount })),
take(5),
toArray
);
const topOrders = firstFiveLargeOrders(orders);
Stream filter and map run on iterators and stop pulling as soon as take(5) collects five matching orders, with toArray materializing only those five.
Compared to lodash/fp and Ramda, which grew up around dynamic JS, fp-pack wins on predictable TypeScript autocomplete; compared to fp-ts, it trades academic depth for a much lower barrier to entry. The npm package even bundles ready-made skills and an add-on for coding agents so AI assistants generate pipe and SideEffect chains out of the box.
Keep two caveats in mind: the 0.16.0 branch is still pre-1.0, so the author occasionally refines types and drops legacy aliases, and the interactive playground on GitHub Pages was built with a Korean UI alongside English docs. If strict typing with minimal runtime overhead is your thing, check out our breakdown of gdp-ts with formal type-level proofs and our note on shrinking JavaScript bundle sizes.
You don't need to rewrite an entire codebase into pure functions or study category theory tonight. Pick one tangled array or API-response transformation, turn it into a linear pipe, and reach for pipeSideEffect or fp-pack/stream only where you genuinely need early exits or lazy iteration.
