DEV Community

Discussion on: Currying in JavaScript

Collapse
 
jesuscovam profile image
jesuscovam

I think the same, but It could be useful for when a param must be computed from other functions, that you might already wrote outside the currying, sor I just my use like this currying(1)(resultOf(2))(3). That's my take in my head.

Collapse
 
jwp profile image
John Peters • Edited

Nice, this makes for placeholder to inject the results of functions.

However, we are also able to do this:

someFunction(1, get2ndParm(), 3);  Which is shorter.

Also, wouldn't currying break the pure function pattern?

Thread Thread
 
macsikora profile image
Pragmatic Maciej

Currying is not pattern. It is function property. In all FP languages functions are like that, so they are curried.

If you have function f: a ->b->c then by applying only a we have function g: b->c.

In JS as it's not FP language we need to make currying manually by using closures and returning function from function. It doesn't violate any purity as it is exactly FP concept.

Thread Thread
 
jwp profile image
John Peters

But has no value as far as I can tell.

Thread Thread
 
macsikora profile image
Pragmatic Maciej

If it would not have value it would not exists. It has huge value. But this answer would be worth a whole post about that ;)

Thread Thread
 
jesuscovam profile image
jesuscovam

maybe the second function would need a valued computed from the first function, so it could be use as a pipeline of computed values that are reusable and can be rearranged as legos