es-toolkit icon indicating copy to clipboard operation
es-toolkit copied to clipboard

Support for `curry`

Open seungrodotlee opened this issue 1 year ago • 6 comments

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

seungrodotlee avatar Jul 08 '24 06:07 seungrodotlee

Sure!

raon0211 avatar Jul 08 '24 12:07 raon0211

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.

evan-moon avatar Jul 13 '24 06:07 evan-moon

@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 avatar Jul 13 '24 12:07 seungrodotlee

@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!

seungrodotlee avatar Jul 14 '24 02:07 seungrodotlee

@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! 👍

evan-moon avatar Jul 15 '24 00:07 evan-moon

Now curry and curryRight have been fully implemented!

D-Sketon avatar Oct 03 '24 10:10 D-Sketon

Thank you @D-Sketon 🙏 Then this issue can be closed now!

evan-moon avatar Nov 13 '24 05:11 evan-moon