I wrote a function called extract, defined as follows:
def extract(params: String): Seq[String] = { val result = params.split(",") map (param => param.trim()) result toSeq }
Then I perform pattern matching on the result of extract, for example:
extract(myInputString) match { case Nil => // do something case head :: Nil => // do something case head :: tail => // do something }
whenever my template matches the case branch Nil => , I get
scala.MatchError: WrappedArray(T) (of class scala.collection.mutable.WrappedArray$ofRef)
on the other hand, if I replaced result toSeq with Seq (result: _ *) in the extraction function, everything will be fine.
Can anyone explain this behavior?
source share