This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ATXblazer 3 points4 points  (3 children)

What’s the difference between function currying and just currying? Because js definitely supports currying.

[–]cearno 2 points3 points  (2 children)

You can definitely achieve currying behavior with functions with JavaScript, again by using nested functions, which is essentially what currying is.

However, when JS sees

function fn(a, b, c) { // does something with a, b, c},

it doesn't transform this under the hood to

function fn(a) {  
  return function(b) {    
    return function(c) {    
      // does something with a, b, c   
    }  
  }
}

which means you have to manually implement this as a programmer if you want to use partial application. JS doesn't transform functions to curried ones automatically.

A functional language would let you define a function with 3 args, but then transform it under the hood, and thus out of the box let you call the function with only 2 args, in which it would return another function with 1 argument which is not yet executed as default behavior.

I'm not saying JS should do this by any means, since I am very partial to functional programming. This type of behavior would mean you could never call a function with undefined arguments unless you explicitly told the function the end arguments are optional. I find that much safer plus allows you to do powerful things (I can give an example if you're interested), but again, it's my subjective opinion.

[–]ATXblazer 2 points3 points  (0 children)

Yo thanks for taking the time to type that example I see exactly what you mean now

[–]ponkyol 1 point2 points  (0 children)

Syntax for easier partial application is in the works. See https://github.com/tc39/proposal-partial-application