You can usually use map
instead of foreach
:
List("a","b","c") foreach println
can be replaced with
List("a","b","c") map println
except forThe only difference is the return type (Unit
vs List[Unit]
), which you aren't interested in anyway when using foreach
.