toss / es-toolkit

A modern JavaScript utility library that's 2-3 times faster and up to 97% smaller—a major upgrade to lodash.
https://es-toolkit.slash.page
Other
6.19k stars 257 forks source link

Support for `curry` #135

Open seungrodotlee opened 2 months ago

seungrodotlee commented 2 months ago

Hello, @raon0211 ! As I mentioned at #133 , I would start work on curry!

raon0211 commented 2 months ago

Sure!

evan-moon commented 1 month ago

I was really happy to hear that es-toolkit decided to support the curry function!!

I'm curious about your thoughts on implementing a strict rule for currying, where if a function takes multiple arguments, it transforms them into a composition of single-argument functions. This approach is a bit different from the lodash specification, which I will explain further.

The curry function in lodash doesn't strictly enforce the rules of currying, and is more like providing partial application rather than true currying.

I think one reason why developers often get confused between currying and partial application is because popular libraries like lodash use these terms incorrectly 😢

Therefore, I would like to suggest designing es-toolkit to follow the correct definition of currying strictly!


However, this might make it harder to gain users since it wouldn't be a drop-in replacement for those who are used to lodash.

seungrodotlee commented 1 month ago

@evan-moon THANK YOU FOR GOOD SUGGESTION! Indeed, the curry method provided by existing libraries like Lodash has a different form compared to the 'strict type of currying'. However, I believe that many developers, including myself, are familiar with the usage of this 'flexible type of currying' provided by these libraries.

In fact, I am now implementing a 'flexible type of currying'. However, after reading your suggestions, I think it is important to respect the traditional method to enhance the depth of the library.

How about this approach?

  1. Implement both 'strict type of currying' and 'flexible type of currying'.
  2. In the documentation, guide developers who want a 'Lodash-style curry' to look for 'flexible type of currying'(ex. curry.flexible or partial.chain).

By implementing it this way, although users might be confused at first, I believe it is a valuable process to correct any misconceptions.

seungrodotlee commented 1 month ago

@evan-moon Based on the suggestions provided and my reply, I have created draft PR #187!

Please check it out and feel free to leave any comments & ideas!

evan-moon commented 1 month ago

@evan-moon Based on the suggestions provided and my reply, I have created draft PR #187!

Please check it out and feel free to leave any comments & ideas!

Thank you. Let's continue the discussion in that PR! 👍