Scala - can a lambda parameter match a tuple?

前端 未结 5 1652
眼角桃花
眼角桃花 2021-02-02 05:42

So say i have some list like

val l = List((1, \"blue\"), (5, \"red\"), (2, \"green\"))

And then i want to filter one of them out, i can do some

5条回答
  •  情深已故
    2021-02-02 06:31

    Hmm although Kipton has a good answer. You can actually make this shorter by doing.

    val l = List((1, "blue"), (5, "red"), (2, "green"))
    val m = l.filter(_._1 != 2)
    

提交回复
热议问题