Scala Collections: map and filter
Scala's standard collections are immutable by default. map builds a new list by applying a function to every element, and filter keeps only the elements for which a condition is true. Neither changes the original list.
Scala
object Main {
def main(args: Array[String]): Unit = {
val scores = List(82, 91, 76)
val curved = scores.map(s => s + 5)
println(curved)
println(curved.filter(s => s >= 90).sum)
}
}