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
0
43
Using Monads for Elegant Error Handling
John Gallagher
October 28, 2021
Tweet
Share
More Decks by John Gallagher
See All by John Gallagher
Fix Production Bugs Quickly - Warsaw Ruby Conference 2024
johngallagher
0
1
Fix Bugs 20x Faster - Belfast Ruby 2025
johngallagher
0
1
Fix Production Bugs 20x Faster - The Wroclave.rb 2025
johngallagher
0
2
Using Monads for Elegant Error Handling - RubyConf 2021
johngallagher
0
1
Fix Production Bugs 20x Faster - Wroclave.rb - 2025
johngallagher
0
3
Squash Production Defects Quickly - The Power Of Structured Logging - EuRuKo 2024
johngallagher
0
2
Other Decks in Programming
See All in Programming
Android 16KBページサイズ対応をはじめからていねいに
mine2424
0
640
レベル1の開発生産性向上に取り組む − 日々の作業の効率化・自動化を通じた改善活動
kesoji
1
350
Startups on Rails in Past, Present and Future–Irina Nazarova, RailsConf 2025
irinanazarova
0
290
20250704_教育事業におけるアジャイルなデータ基盤構築
hanon52_
5
1.2k
AI コーディングエージェントの時代へ:JetBrains が描く開発の未来
masaruhr
1
210
ソフトウェア設計とAI技術の活用
masuda220
PRO
25
6.7k
[SRE NEXT] 複雑なシステムにおけるUser Journey SLOの導入
yakenji
0
740
TypeScriptでDXを上げろ! Hono編
yusukebe
3
860
テスト駆動Kaggle
isax1015
1
880
階層化自動テストで開発に機動力を
ickx
1
410
Git Sync を超える!OSS で実現する CDK Pull 型デプロイ / Deploying CDK with PipeCD in Pull-style
tkikuc
4
450
Streamlitで実現できるようになったこと、実現してくれたこと
ayumu_yamaguchi
2
220
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
329
21k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
KATA
mclloyd
30
14k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
50
5.5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Into the Great Unknown - MozCon
thekraken
40
1.9k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
990
The Cult of Friendly URLs
andyhume
79
6.5k
Gamification - CAS2011
davidbonilla
81
5.4k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Being A Developer After 40
akosma
90
590k
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