Skip to content

Instantly share code, notes, and snippets.

@ahmedelgabri ahmedelgabri/curry.js
Last active Jan 20, 2018

Embed
What would you like to do?
fmap = (f => g => x => (f (g (x))))
curryOnce = (f => x => (...xs) => (f (x, ...xs)))
curry = (n => f => (
(n === 1) ?
(f) :
(fmap (curry (n - 1)) (curryOnce (f)))))
method = (m => (m.call.bind (m)))
methodWithArgs = (n => m => (curry (n) (method (m))))
flip = (f => x => y => (f (y) (x)))
split = (methodWithArgs (2) (''.split))
map = (flip (methodWithArgs (2) ([].map)))
;;;
(console.log
(map (x => (x * 2))
(split ('1 2 3 4 5') (' '))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.