pipe([1, 2, 3], map(multiply(3))); //=> [3, 6, 9]
// = Early termination with lazy evaluation =
pipe(
hugeArray,
map(expensiveComputation),
filter(complexPredicate),
// Only processes items until 2 results are found, then stops.
// Most of hugeArray never gets processed.
take(2),
);
// = Custom logic within a pipe =
pipe(
input,
toLowerCase(),
normalize,
($) => validate($, CONFIG),
split(","),
unique(),
);
// = Migrating nested transformations to pipes =
// Nested
const result = prop(
mapValues(groupByProp(users, "department"), length()),
"engineering",
);
// Piped
const result = pipe(
users,
groupByProp("department"),
mapValues(length()),
prop("engineering"),
);
// = Using the 3rd param of a callback =
// The following would print out `data` in its entirety for each value
// of `data`.
forEach([1, 2, 3, 4], (_item, _index, data) => {
console.log(data);
}); //=> "[1, 2, 3, 4]" logged 4 times
// But with `pipe` data would only contain the items up to the current
// index
pipe(
[1, 2, 3, 4],
forEach((_item, _index, data) => {
console.log(data);
}),
); //=> "[1]", "[1, 2]", "[1, 2, 3]", "[1, 2, 3, 4]"