I have looked into writing streams-based code in Java 8, and have noticed a pattern, namely that I frequently have a list but have the need to transform it to another list by applying a trivial mapping to each element. After writing .stream().map(...).collect(Collections.toList())
yet another time I remembered we have List.forEach
so I looked for List.map
but apparently this default method has not been added.
Why was List.map()
(EDIT: or List.transform()
or List.mumble()
)
not added (this is a history question) and is there a simple shorthand using other methods in the default runtime library that does the same thing that I have just not noticed?