Skip to content

Instantly share code, notes, and snippets.

@aonghusonia
Last active May 9, 2018 16:56
Show Gist options
  • Save aonghusonia/d25a46d9ce0da237768cb0c909030f82 to your computer and use it in GitHub Desktop.
Save aonghusonia/d25a46d9ce0da237768cb0c909030f82 to your computer and use it in GitHub Desktop.
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) =>
(err, ...xs) => err
? args[args.length - 1](err)
: fn(...xs, acc),
args[args.length - 1]
)(null, ...args.slice(0, -1));
const trampoline = func => arg => {
let value = func(arg);
while (typeof value === "function") {
value = value();
}
return value;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment