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?

  • 2
    Many languages only allow you to return one thing from a function, not multiple things. – Robert Harvey Jan 22 '16 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 Jan 22 '16 at 15:26
  • 1
    Not 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 Jan 22 '16 at 15:28
  • what is "currying"? – BЈовић Jan 22 '16 at 15:29
  • 2

There's multiple reasons:

  1. Some functions will return tuples and it's useful to compose such functions directly with other functions that accept tuples.

  2. 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.

  3. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.