I'm doing some pattern matching on a colon delimited String as follows:
case s:String => s.split(":") match {
case Array("foo","bar") => ...
case Array("hello",_,_) => ...
...
}
How can I rearrange the code to assign a name to the array returned by s.split(":")
?
I've tried the following to no avail:
case s:String => val x = s.split(":") match {
case Array("foo","bar") => // try to use x here
...
}
case s:String => s.split(":") match {
case x @ Array("foo","bar") => ...
case x @ Array("hello",_,_) => ...
...
}
Or
case s:String =>
val x = s.split(":")
x match {
case Array("foo","bar") => ...
case Array("hello",_,_) => ...
case Array(aStr, "bar") => println(aStr.toUpperCase)
...
}
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