Hacker News new | past | comments | ask | show | jobs | submit login

To me the problem with this kind of explanations is that they miss the “why”. I understand “what” is currying and “how” to implement it. But I’m missing the “why”.

The real-world example doesn’t tell me why I would prefer currying instead of putting the date at the end and making it optional, then checking if missing to assign current date. And for the other argument I could create separate functions logDebug, logWarning and logError, those would call the generic function with fixed strings, right?




We use currying at work to inject dependencies. E.g.

`sendEmail(mockEmailService)(to, subject, body) `

I find it helps to differentiate between side-effecting dependencies and parameters, making code purer, easier to test, more scalable etc.


>And for the other argument I could create separate functions logDebug, logWarning and logError, those would call the generic function with fixed strings, right?

Sure, but what would you do if e.g. the importance string isn't fixed? Well, you might write a function that takes in the importance string and returns a function that calls the generic function with the dynamic string. That's currying.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: