Skip to content

Instantly share code, notes, and snippets.

@alvaropinot
Last active May 31, 2017 08:02
Show Gist options
  • Save alvaropinot/d9f3f6181998161122722aa005102564 to your computer and use it in GitHub Desktop.
Save alvaropinot/d9f3f6181998161122722aa005102564 to your computer and use it in GitHub Desktop.
curry and pipe playground
const pipe = (...functions) => startingValue => functions.reduce((actualValue, fn) => fn(actualValue), startingValue)
const sumTwo = (a) => a + 2
const mult = (a) => a + 2
const repeat = times => fn => Array(times).fill(fn)
const doTimes = times => fn => x => pipe(...repeat(times)(fn))(x)
const sumTwo4Times = doTimes(4)(sumTwo)
sumTwo4Times(4)
// var curry = (fn) => (...args) => () => fn(...args)
const curry = function (fn) {
const arity = fn.length
return function resolve (...args) {
console.log(args)
return args.length === arity ?
fn(...args) :
// function (foo) {
// console.log(foo)
// }
function (...foo) {
return resolve([...args, ...foo])
}
}
}
const sum = function(a, b) {
return a + b;
}
curry(sum)(2, 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment