New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pattern matching in argument lists #7909
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7909?orig=1 |
@retronym said (edited on Oct 12, 2013 9:08:45 PM UTC): http://stackoverflow.com/questions/16326434/is-destructuring-input-parameters-available-in-scala |
@retronym said: def setAdd(a : (List[Char], Char)) : List[Char] = {
val (l, c) = a
if (l contains c) l else c :: l
} |
@retronym said: |
Jörg Weisbarth (marcus-aurelius) said (edited on Oct 13, 2013 9:49:38 AM UTC): |
Jörg Weisbarth (marcus-aurelius) said: |
A request like this (nowadays) should be discussed on the forums first, and then see if there's interest in Scala 3 (Dotty). |
At the moment it is not possible to use pattern matching also in arguments for function definitions as it is possible eg. in Haskell.
I would love to write function definitions like this:
def foo((l, c) : (List[Char], Char), /other arguments/) : List[Char] = /body/
for example (just for illustration, function doesn't have any deep sense):
def setAdd((l, c) : (List[Char], Char)) : List[Char] = if (l contains c) l else c :: l
useful also in anonymous function definitions.
At the moment you have to write:
def setAdd(a : (List[Char], Char)) : List[Char] = if (a._1 contains a._2) a._1 else a._2 :: a._1
The text was updated successfully, but these errors were encountered: