Scala 点滴:“@”绑定变量

来源:互联网 发布:java web pdf百度云 编辑:程序博客网 时间:2024/06/04 01:16

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)}
0 0