Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Using Monads for Elegant Error Handling
Search
John Gallagher
October 28, 2021
Programming
47
0
Share
Using Monads for Elegant Error Handling
John Gallagher
October 28, 2021
More Decks by John Gallagher
See All by John Gallagher
Fix Production Bugs Quickly - Warsaw Ruby Conference 2024
johngallagher
0
6
Fix Bugs 20x Faster - Belfast Ruby 2025
johngallagher
0
5
Fix Production Bugs 20x Faster - The Wroclave.rb 2025
johngallagher
0
5
Using Monads for Elegant Error Handling - RubyConf 2021
johngallagher
0
6
Fix Production Bugs 20x Faster - Wroclave.rb - 2025
johngallagher
0
5
Squash Production Defects Quickly - The Power Of Structured Logging - EuRuKo 2024
johngallagher
0
5
Other Decks in Programming
See All in Programming
Migration to Signals, Signal Forms, Resource API, and NgRx Signal Store @Angular Days 03/2026 Munich
manfredsteyer
PRO
0
230
Xdebug と IDE による デバッグ実行の仕組みを見る / Exploring-How-Debugging-Works-with-Xdebug-and-an-IDE
shin1x1
0
330
20260320登壇資料
pharct
0
160
ポーリング処理廃止によるイベント駆動アーキテクチャへの移行
seitarof
3
1.3k
Geminiをパートナーに神社DXシステムを個人開発した話(いなめぐDX 開発振り返り)
fujiba
0
130
Coding as Prompting Since 2025
ragingwind
0
680
Strategy for Finding a Problem for OSS: With Real Examples
kibitan
0
130
ファインチューニングせずメインコンペを解く方法
pokutuna
0
260
The free-lunch guide to idea circularity
hollycummins
0
410
AI駆動開発がもたらすパラダイムシフト
ryosuke0911
0
110
Smarter Angular mit Transformers.js & Prompt API
christianliebel
PRO
1
120
Codex CLIのSubagentsによる並列API実装 / Parallel API Implementation with Codex CLI Subagents
takatty
2
820
Featured
See All Featured
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.2k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
170
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
53k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
130
Claude Code のすすめ
schroneko
67
220k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.9k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Designing for humans not robots
tammielis
254
26k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
160
Agile that works and the tools we love
rasmusluckow
331
21k
Transcript
Using Monads for Elegant Error Handling John Gallagher
None
None
None
None
None
None
Failure modes? Caught all exceptions? Customer experience?
Example - Address Editing Find contact Lookup postcode* Success? Render
manual entry Render select Success? Render error Yes Yes No No * Postcode - zip code in the US
Exceptions
Exceptions
Exceptions
Problems Returning nil harmful Client knows too much No return
value convention Customers: broken software You: doubt, decision fatigue
What is a Result Monad? Represents success or failure Consistent
interface Wraps value or error
Refactor to Monads
Success and Failure
None
None
Exceptions
Monads
Exceptions
Monads
Exceptions
Monads
Convert to pipeline
Handle success with .fmap
None
None
Handle failure with .or
None
None
Chain .fmap and .or
None
None
Monads
Monads and Pipeline
Exceptions Monads
None
Turn it up to eleven!
Turn it up to eleven!
Benefits Readable pipeline Scales well Helps thinking Failures store errors
Drawbacks More boilerplate code More dependencies Not idiomatic Ruby More
to understand
None
Quiz
Question 1 Answer: C
Question 2 Answer: A
Practice https://bit.ly/eleganterrors Run through the exercise Submit a PR Ask
any questions
Thank you! John Gallagher Lead Developer, BiggerPockets Automation Consultant, Synaptic
Mishap Twitter: @synapticmishap LinkedIn: @synapticmishap Github: @johngallagher
Do notation Try Check out the docs for Dry Monads