Skip to content

Instantly share code, notes, and snippets.

View aonghusonia's full-sized avatar

Aonghus O Nia aonghusonia

  • Milton, MA, USA
View GitHub Profile
@aonghusonia
aonghusonia / varg.js
Created May 10, 2018 16:06
vargs node variable number of arguments with a callback
const varg = (fn, arity) => (...args) => {
const l = args.length < arity ? args.length : arity;
return typeof args[l - 1] === 'function'
? fn(
...args.slice(0, -1),
...new Array(arity - l).fill(undefined),
args[l - 1]
)
: fn(...args, ...new Array(arity - args.length).fill(undefined));
};
@aonghusonia
aonghusonia / helpers.js
Last active May 9, 2018 16:56
helper functions
const wait = ms => x => new Promise(resolve => setTimeout(resolve, ms, x));
const pipeP = (...fns) => x =>
fns.reduce((p, fn) => p.then(fn), Promise.resolve(x));
const pipe = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x);
const pipeC = (...fns) => (...args) =>
fns.reduceRight(
(acc, fn) =>