检查集合中的所有项目是否与Scala中的谓词匹配

时间:2013-04-10 17:06:15

标签: scala predicate

测试集合中所有项目是否与谓词匹配的最惯用的方法是什么?

任何项目?

1 个答案:

答案 0 :(得分:58)

这里有内置函数:

List(1,2,3,4).forall(x => x < 5)
res0: Boolean = true

任何:

List(1,2,3,4).exists(x => x > 3)
res1: Boolean = true
相关问题