In languages that support currying, I can't think of many cases where using a tuple as function input parameters would be better than breaking the tuple apart into multiple parameters, which then allows you to enjoy the full power of currying. In which situations is keeping a tuple as function parameter better than breaking it apart? (Apart from the situation where the input originally was already in tuple form) Does such situation occur a lot in production code?
-
2Many languages only allow you to return one thing from a function, not multiple things.Robert Harvey– Robert Harvey01/22/2016 15:24:26Commented Jan 22, 2016 at 15:24
-
@RobertHarvey Edited the question a bit. Surely I mean languages that support currying. Also I think I'm specifically interested in input parameters here. I saw some Scala code which made the input parameters into a tuple which seems to be a hindrance for my purpose.xji– xji01/22/2016 15:26:01Commented Jan 22, 2016 at 15:26
-
1Not all functions benefit from currying, and passing in a single object can be convenient. You're never obligated to follow someone else's coding style, unless it's part of a shop standard.Robert Harvey– Robert Harvey01/22/2016 15:28:54Commented Jan 22, 2016 at 15:28
-
what is "currying"?BЈовић– BЈовић01/22/2016 15:29:24Commented Jan 22, 2016 at 15:29
-
2en.wikipedia.org/wiki/CurryingRobert Harvey– Robert Harvey01/22/2016 15:29:50Commented Jan 22, 2016 at 15:29
1 Answer 1
There's multiple reasons:
Some functions will return tuples and it's useful to compose such functions directly with other functions that accept tuples.
Often when values are bundled in a tuple they're conceptually one unit, i.e. you almost always pass all of them together. In other words, there's certain functions you wouldn't curry often.
It's trivial to write functions that turn a tuple-accepting function in a curried function and vice-versa, so it's never a big issue even if you need to curry a tuple-accepting function.
Explore related questions
See similar questions with these tags.