functional programming - Create two lists from one by condition in scala -
this question has answer here:
- how split sequence 2 pieces predicate? 5 answers
how create 2 lists 1 using condition in scala. using filter i'll single list, maybe function returning tuple?
there function called partition:
def partition(p: (a) ⇒ boolean): (list[a], list[a])
i guess want.
example:
scala> (0 10).tolist res0: list[int] = list(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) scala> res0.partition(_ < 5) res1: (list[int], list[int]) = (list(0, 1, 2, 3, 4),list(5, 6, 7, 8, 9, 10))
Comments
Post a Comment