Last active
May 9, 2018 16:56
-
-
Save aonghusonia/d25a46d9ce0da237768cb0c909030f82 to your computer and use it in GitHub Desktop.
helper functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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