scala - Filter matching and non-matching elements into different halves of a tuple -
is there simple , efficient way perform following in scala?
val elements = list(1, 2, 3, 4, 5, 6) val (odd, even) = elements.filter(_ % 2 == 0)
i aware of groupby
, works constant number of groups can extracted separate values.
list.partition
want:
val (even, odd) = elements.partition(_ % 2 == 0)
note works 2 final groups.
Comments
Post a Comment