scala-library-next
scala-library-next copied to clipboard
Map builders do not expose methods to add elements without tupling
Scala 2.13.x
As noted by @smarter here, builders for Maps just use the regular Builder interface, and do not expose a way to add elements without creating tuples. However, several of the implementations (which are not publicly accessible) do have addOne methods taking key and value parameters.
What's more concerning to me is how Map creates a Tuple2 for every MapNode iteration, like map, foreach etc. for most Map implementation.
In HashMap, MapKeyValueTupleIterator creates a Tuple2 for every pair during iteration. So if you do a map on a HashMap with 1000 elements, it creates additional 1000 Tuple2 (if there is no collision because that's a different node impl)