Coding时,我们用过太多的case head :: tails => ???
。此种方式,对于我们操作List
实现类似尾递归算法非常方便。但是,除了List
,对于其他Collection
我们没有了::
操作符,怎么实现上面形式的pattern match呢?
- Concept:match type &
@
bind variable - Example:
array match {
case Stack(head, tails @ _*) => (head, tails)
}
stack match {
case Stack(head, tails @ _*) => (head, tails)
}
queue match {
case Stack(head, tails @ _*) => (head, tails)
}