HOW TO EXTEND MAP? ... OR WHY WE NEED COLLECTIONS REDESIGN?
summary
Extending Scala's Map to a Grid (Map[(Int,Int),V] with row) breaks in practice because covariance and builders change return types: filter/map/flatMap use the collection builder so they return Map, not Grid. Fixes require implementing MapLike with adjusted type parameters, providing an implicit CanBuildFrom, and reimplementing withDefault variants; a subtle bug leaves empty inner maps (a memory leak). Practical advice is to prefer composition and minimal overrides rather than inheriting the full collections hierarchy.
AI-written summary · about
chapters (15)
- 0:00Introduction
- 0:46The problem
- 2:29The collections
- 4:11Immutable map
- 6:49Interface
- 7:35Methods
- 11:07Code
- 12:12Testing
- 13:30Filter method
- 15:34Map method
- 18:17With default
- 19:17Recap
- 20:52Goals for new implementations
- 23:52Memory leak
- 26:39References
related talks
51mImplementing the Scala 2.13 collections
37mWhat’s in the next iteration of the standard collections?
34mScalaz 102 Level Up Your Scalaz Foo!
41mMigrating to Scala 2.13
46mImmutable Sequential Maps – Keeping order while hashed
35mMigrating to Scala 2.13
39mA few tips on modelling things in Scala
01h 03mIntro to FP in Scala: Exploring a Toolbox for Solving Problems - Part 4 of 6
