Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个列表,想用它来生成三个列表。我可以通过两种过滤器应用来做到这一点:
val z_out = zs.filter(p1) val z_in = zs.filter(p2) val z_split = zs.diff(z_out union z_in)
我可以通过一次遍历列表来做到这一点吗?如:
val (z_out, z_in, z_split) = zs.foldLeft(...)
你可以,只要 fold 的结果是一个元组:
scala> val (a,b,c) = Nil.foldLeft((1,2,3))((x,y) => x) a: Int = 1 b: Int = 2 c: Int = 3