Spotting Pure Functions in I/O Driven Code
summary
Claim: separating pure logic from IO makes code testable, refactorable and removes subtle bugs. Refactor of a food-ordering service in Scala pulls current time out as an explicit argument, finds a pure hours.encloses function, caches dayOfWeek to avoid rare clock-rollover bugs, and moves DB calls into an IO wrapper with run, map and flatMap used via for-comprehensions. Result: pure validators become trivially table-tested and facades return composable effect descriptions while actual IO runs only at the endpoint.
AI-written summary · about
chapters (9)
- 0:00Welcome and introduction
- 1:55From OOP to functional programming
- 7:37Pure functions vs IO
- 12:38Refactoring spaghetti code
- 18:01Composing pure functions
- 22:17Separating IO and logic
- 24:50Introducing IO wrapper
- 33:37Summary and conclusions
- 38:19Q&A and closing
related talks
45mFunctional Refactoring: How to Approach It
34mHow I learned to stop worrying and love Functional Design
01h 06mThe Joy of Functional Programming
34mThe Hitchhiker Guide to Pure Functions and Immutable Objects
42mPure Functions and Immutable Objects
01h 00mLogic vs. side effects: functional goodness you don't hear about
01h 00mWhat The Functional Programming
01h 01mLeaving side effects aside
