MatchError when match receives an IndexedSeq but not a LinearSeq

前端 未结 2 524
暖寄归人
暖寄归人 2020-12-12 00:20

Is there a reason that match written against Seq would work differently on IndexedSeq types than the way it does on LinearSeq

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 01:22

    Followed pattern match works for List, Seq, LinearSeq, IndexedSeq, Vector.

      Vector(1,2) match {
      case a +: as => s"$a + $as"
      case _      => "empty"  
    }
    

提交回复
热议问题