I have a list:
val list1 = List("male:Adam", "male:Peter", "female:Jane", "female:Sue", "female:Jo", "other:John")
I want to create two lists, one of female names and one of male names. i.e.:
List("Adam", "Peter")
List("Jane", "Sue", "Jo")
I've done this with
val result = list1.groupBy(_.startsWith("male"))
So that result
has the two lists mapped against true
and false
but with each element being "male:Adam"
etc. But then I'd have to cycle through each list removing the male:
and female:
strings. This smells of non-functional.
Can anyone show how the above problem would be solved in a functional way?