Currying in JavaScript: Fun for the Whole Family!
Programming
|
As I've said before, I'm quite partial to JavaScript. Lately, I've been reading about currying functions, so let's see if currying can be done in JavaScript.
The begs the question, What is currying? Currying is a technique to transform a function that takes some number of arguments to a function that takes fewer. The process was named after the logician Haskell Curry. The goal is to get something that works like this:
When we pass fewer than the required number of arguments, it returns a function that takes the remaining arguments. Once we pass the correct number of parameters, it evaluates the function.
Before possibly reinventing the wheel, I looked online to see if anyone had done this. While there are plenty of JavaScript functions that claim to curry, they all get it wrong. They do something like this (using the same add from above):
They do get the add_3 function in the end, but all they do is create a new function with View In Full
 |
7 Comments |
9.00 out of 10 |
|
|
|
 |
Chris Bouchard (23) United States, New York |
|
|
neko-mangaka has 0 fans
become a fan |
|
 |
|
|
 |
|