0:00 / 0:00
Introducing the Reader Monad - Functional Kotlin
Pairing with Duncan
4.5K subscribers • 15 videos on Hallway
- Recommended by 1 person: 1 in engineering communities.
- Presented by Duncan
- Linked in the descriptiondmcg/gilded-rose-tdd
Advanced. Deep dive for people who know the field.
2.1K views3 years ago1 recommendation
Programming languagesSoftware designKotlinFunctional programmingDesign patterns
Duncan refactors Kotlin code to use the Reader monad as an alternative functional approach for providing transaction context.
In our last episode (youtu.be/uZdKRSkiWjc) we looked at using Kotlin context receivers to provide transactions to functions that need them. Uberto Barbini's upcoming book, From Objects to Functions (pragprog.com/titles/uboop/from-objects-to-functions/) details a more traditional functional approach to providing context - the Reader Monad. We would like to understand more about this approach, so in this episode we backtrack a little, refactoring code that takes a transaction as a parameter to instead return a RequiresTransaction type, and then refactor that to a Reader monad. This is part 64 of an exploration of where a Test Driven Development implementation of the Gilded Rose stock control system might take us in Kotlin. You can see the whole series as a playlist youtube.com/playlist?list=PL1ssMPpyqociJNwykAOB9_KEZVW7BW7m2 and the code on GitHub - this particular experiment is on a branch github.com/dmcg/gilded-rose-tdd/tree/plain-reader-monad There is another version (youtu.be/mjVL1xQ7oPc) of this topic that derives Reader from context receivers code. It probably makes less sense, especially if you haven't internalised context receivers; but if you've come here from a future where context receivers are commonplace, who knows, it might be a better bet. If you like this, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook (java-to-kotlin.dev). It's about far more than just the syntax differences between the languages - it shows how to upgrade your thinking to a more functional style. I have some free time between producing videos and working for team Gilded Rose. If you like these videos I'd like to work with you - please get in touch - duncan@oneeyedmen.comWhy it's here
1 person recommends thisWhat people say. Recommended as a clear walkthrough of implementing and using the Reader monad in Kotlin.