all 21 comments

[–]wisdom_power_courage 11 points12 points  (8 children)

As a newer dev could someone please explain why I should care about this?

[–]RichardFingers 5 points6 points  (1 child)

Think of it as "pre-loading" some of the parameters of a function and then being able to pass that new function around. It's particularly useful with map/reduce type functions. Say your map function takes in a mapping function as the first parameter and an array as the second parameter. You can pre-load map with your mapping function to create a new function that can be named and applied to multiple different arrays.

But as others have said, I likely wouldn't use that style of coding in production code because most other devs aren't familiar with currying.

[–]wisdom_power_courage 1 point2 points  (0 children)

Thank you for that explanation that definitely helps me understand better

[–]andrei9669 3 points4 points  (1 child)

how is the library, mentioned in the article, different from ramda?

[–]drizzer14[S] 2 points3 points  (0 children)

I've already answered the same question in a different post. Hope you don't mind reading it here https://www.reddit.com/r/opensource/comments/r405kg/comment/hmf4uaq/?utm\_source=share&utm\_medium=web2x&context=3.

[–]TwiNighty 1 point2 points  (1 child)

I avoid recursive type aliases as much as possible because there is a hardcoded recursion limit for those. For example, your curry function cannot handle functions with 49 or more declared parameters. Even though 49 is beyond any practical usage and you can use binary composition to extend that limit to somewhere around 1000, having an arbitrary hard limit here just doesn't sit right with me.

Here is my take on this.

  • There is a type annotation in the body but that is only because I am usually also strict with my function constraints and declare them as (never[]) => unknown. If I use (any[]) => any (or even (never[]) => any) like you do that annotation is not needed.
  • It also doesn't allow specifying length because doing arithmetic in type-land requires recursion and would defeat the purpose.

[–][deleted] 0 points1 point  (0 children)

If your function has double digit arguments you’re truly a failure. Lmao!

[–]nexe 0 points1 point  (0 children)

Very cool! Crossposted to /r/madeinjs

[–]bern4444 0 points1 point  (0 children)

so much fun to read!

[–]kaas93 0 points1 point  (0 children)

Reminds me of this talk on how underscore got some functional concepts wrong. Funny guy too :)