I have List[Int] in Scala. The List is List(1,2,3,4,5,6,7,8,9,10). I want to filter the list so that it only has even numbers. And I w
List[Int]
List(1,2,3,4,5,6,7,8,9,10)
filter
A for comprehension (which internally unfolds into a combination of map and withFilter) as follows,
map
withFilter
for (x <- xs if x % 2 == 0) yield x*2
Namely
xs.withFilter(x => x % 2 == 0).map(x => x*2)