ParArray
is a parallel structure. Its main usecase is to operate on the elements concurrently (see docs). That's done (roughly speaking) by concurrently applying operations on arbitratry segments of the ParArray.
For the sake of a counter example, imagine that you could unapply on ParArray. How would the match look like:
Given val b = ParArray("a","b","c","d")
b match {
case ParArray(_,"b",_) => 2
case _ => -1
}
Could be arbitrarily converted into:
//Parallel split & join:
"a","b" match {
case ParArray(_,"b",_) => 2
case _ => -1
}
"c","d" match {
case ParArray(_,"b",_) => 2
case _ => -1
}
Which of course, doesn't make sense.
For the specific case on your question, you could use direct addressing:
if (b.size == 3 && b(1)=="b") 2 else -1
In a more generic sense, a good way of reasoning is thinking of how your operation could be applied to all elements at the same time.
If you need to match
on structure, you could obtain an array with the parArray.toArray
method. You should also question why is a ParArray
being used.