Functional refactoring
summary
Refactors a messy MongoDB-backed update for a chess user into composable functions that push the collection dependency out and eliminate deep nesting, building a small container with apply/map/flatMap/pure and a tag system to prevent mixing collections. Prototype implements a Reader-style DB wrapper and an Option transformer, then swaps to Scalaz ReaderT and MongoDB collection tagging, producing linear for-comprehension code, externalized dependency injection via a resolver, and working code that cuts three nested levels to one.
AI-written summary · about
chapters (11)
- 0:00Introduction to refactoring
- 3:08Problems with current code
- 7:12Dependency inversion approach
- 10:26Tagging collections for type safety
- 13:18Creating DB reader container
- 17:48Handling Option with transformer
- 21:04Dependency resolver implementation
- 24:59Program execution context
- 27:06Introducing Reader monad
- 30:18Final refactoring with Reader
- 33:07Summary and Q&A
related talks
45mFunctional Refactoring: How to Approach It
42mTaking inspiration from the functional world
39mA roadtrip with monads: from MTL, through tagless to BIO
35mIntroducing Typelevel Scala into an OO environment
26mFrom OO Patterns to Functional Programming w/o Killing Yourself
31mAbstract your representation and fix your functors
34mPatterns of a pragmatic functional architecture
49mMining Functional Patterns
