Created
August 3, 2016 05:22
-
-
Save stefanfrede/a6c14ff422257b3cdfb46c50cb27880c to your computer and use it in GitHub Desktop.
flipAndCurry is a function that takes a function as argument, “flips” the order of arguments around, and then curries it.
This file contains hidden or 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 flipAndCurry = (fn) => | |
(first) => (second) => fn(second, first); | |
// Example: | |
// https://gist.github.com/stefanfrede/596597d8b544de08491364eab20053c6 | |
const mapWith = flipAndCurry(map); | |
// flipAndCurry throws the current context away, so it can’t be used to flip methods. | |
// A small alteration gets the job done: | |
const flipAndCurry = (fn) => | |
(first) => | |
function (second) { | |
return fn.call(this, second, first); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment