Reputation: 461
List(1,2,3,4,5) partition (_ % 2 == 0)
produces
res40: (List[Int], List[Int]) = (List(2, 4),List(1, 3, 5))
How do I access the lists individually. res40(0) does not seem to work.
Upvotes: 1
Views: 86
Reputation: 3863
You can do this to assign each partition to a different val
val (even, odd) = List(1,2,3,4,5) partition (_ % 2 == 0)
Upvotes: 2
Reputation: 214927
partition
creates a pair/tuple, and you can use ._1
, ._2
, etc to access elements in scala tuples, see related question:
res0._1
# res2: List[Int] = List(2, 4)
Upvotes: 1