The Functional Fix: Kotlin Error Handling Made Elegant
summary
Refactors a procedural Kotlin HTTP-request matcher used in Specmatic into a Railway Oriented composition that returns an Either monad and chains via flatMap/fold; implements a small plumbing API — pipe/then/handleError — then replaces it with native Arrow KT flatMap composition. Example composes matchUrl → matchMethod → matchBody to pass the request along on success or short‑circuit with an error; takes about a week to prototype and is reused, but adds overhead so it pays off mainly for long chains (≈10 functions), not tiny ones.
AI-written summary · about
chapters (8)
- 0:00Introduction
- 1:33The problem statement
- 5:30Railway oriented programming
- 10:06Code transformation journey
- 25:03Understanding monads
- 29:53Applying flatMap and fold
- 36:25Refining the final solution
- 39:09Q&A and conclusion
related talks
47mFunctional programming in Kotlin: exploring Arrow
48mKotlin & Functional Programming: pick the best, skip the rest
39mA Result for Our Issues
44mKotlin & Functional Programming: pick the best, skip the rest
43mError Handling Strategies for Kotlin Programs
29mTreasure.map(): Functional Programming in Kotlin
41mArchitectures Using Functional Programming Concepts
41mAn Arrow to the Kotlin
