Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion js/src/dataTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ interface Transformer<TInput, TOutput> {
}

function pipeline<T>(value: T, ...fns: Array<(arg: T) => T>): T {
return fns.reduce((acc, fn) => fn(acc), value);
// Fast path for no functions
if (fns.length === 0) return value;

let result: T = value;
for (let i = 0, len = fns.length; i < len; ++i) {
result = fns[i](result);
}
return result;
}

function groupBy<T>(items: T[], keyFn: (item: T) => string): Record<string, T[]> {
Expand Down
Loading