-
-
Save lvivski/5452414 to your computer and use it in GitHub Desktop.
сurry.js for 140byt.es
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
function curry(fn, context, args, a) { // fn — function to curry, context — calling context | |
args = args || [] | |
return function () { // args are empty if none, return function | |
return (a = arguments).length // if arguments length | |
? curry.call(this, fn, context, args.concat.apply(args, a)) // curry function with more arguments | |
: fn.apply(context, args) // call function in context | |
} | |
} |
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
function _(f,c,g,a){g=g||[];return function(){return 0 in(a=arguments)?_.call(_,f,c,g.concat.apply(g,a)):f.apply(c,g)}} |
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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2013 Yehor Lvivski <[email protected]> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
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
{ | |
"name": "curry.js", | |
"description": "Curry", | |
"keywords": [ | |
"functional", | |
"haskell", | |
"curry" | |
] | |
} |
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
<!DOCTYPE html> | |
<title>Curry.js</title> | |
<div>Expected value: <b>5</b></div> | |
<div>Actual value: <b id="ret"></b></div> | |
<script> | |
var myFunction = function _(f,c,g,a){g=g||[];return function(){return 0 in(a=arguments)?_.call(_,f,c,g.concat.apply(g,a)):f.apply(c,g)}} | |
document.getElementById( "ret" ).innerHTML = myFunction(Math.max, null)( 1, 2, 3 )( 5 )( 4 )() | |
</script> |
Wow, thanks!
You're welcome!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Save 1 byte by definining g before return (save the brackets), another one by replacing ".length" with "0 in":