From what I have understood:
Currying - functions returning functions
string.capitalize(1)('character')('at the end')
Method chaining - methods returning objects
string.lowercase.capitalize.uppercase
Is this understanding correct?
If so, are there cases one of them is better than the other?
Cause it seems to me that method chaining is better and more readable. You also have autocompletion showing what methods you can use if you hit "dot" and it will show all the arguments you can pass.
A better equivalent of currying would be the Builder design pattern.
Ergo, you would do something like:
myObject.setIndexRangeToEffect(1,1).setTextTransformation(UPPERCASE).execute();
At any point before calling execute
, you essentially have a "curried" action object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With