UNPKG

@mvst/ts-unions

Version:

TypeScript union types for Maybe and RemoteData with pattern matching

18 lines (17 loc) 529 B
export function curry(fn) { return function curried(a, b) { // If both args passed, Call directly if (arguments.length >= 2) { // `b!` is safe because we know arguments.length >= 2 return fn(a, b); } // Otherwise return a function awaiting `b` return (b) => fn(a, b); }; } export function compose(...fns) { return (x) => fns.reduceRight((acc, fn) => fn(acc), x); } export function pipe(...fns) { return (x) => fns.reduce((acc, fn) => fn(acc), x); }