Skip to content

Instantly share code, notes, and snippets.

@ahmedelgabri
Last active January 20, 2018 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmedelgabri/0e1e94751aaec99a0afa35f6332431d2 to your computer and use it in GitHub Desktop.
Save ahmedelgabri/0e1e94751aaec99a0afa35f6332431d2 to your computer and use it in GitHub Desktop.
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