Monads in practice

Christophe Marchal
Christophe MarchalDevOps Software Architect at ilegra
Monads in Practice 
Christophe Marchal | Software Architect
A couple of links 
christophe.marchal@ilegra.com 
@toff63 
http://github.com/toff63 
http://francesbagual.net
Disclaimer
Manage complexity with Monad
Study Monads online is hard
Academic talks 
Functor 
Monoids 
Monads 
Category 
theory
Category Theory
Function 
Monoids 
Associative 
( 1 + 2 ) + 3 = 1 + ( 2 + 3 ) 
InitiAl Value 
Result stay in the same 
category
Monoid Example
Monoid
Functor 
Things that can be map over 
capacity BEHaviour 
map
Functor: Example
Functor: Example
Monads
Problem it solves
Scenario 
F 1 F 2
sweet 
Monads Rules: function to create it
Broken Composition 
F 1 
F 2 sweet
Monads Rules: You need a Functor 
F 1 
map ( f 2 ) 
sweet
Scenario 
F 1 F 3 
sweet
Problem: Nested Monad 
F 1 
sweet 
map ( f 3 ) 
sweet
F 1 
sweet 
Flatmap ( f 3 ) 
Monads Rules: You need a Flatmap
Monads in practice
Business rule 
TRUE False 
age > 18 
Authorized Not 
Authorized
Business rule implementation
What we want
Monad (?) Code
Trade-off 
More code than before 
Better API 
Easy to reuse 
Potential complexity Managed
Traditional Code
Side Effect 
Our method can return either a sequence 
either null
Exist 
? 
TRUE False 
null ? 
Riendutout quelquechose
Encapsulating if null with Option
Creating our OptionBagual
Code with Options
Business code
Side Effect 
Our method can return either an option 
[sequence] either throw an exception
Try! 
Success Failure 
Try to 
execute 
Gremio Inter
Encapsulating try/catch with Try
Encapsulating try/catch with Try
Code with Try
Business code
Connection Handling
No silver bullet
Loan Pattern
Final Code
Conclusion 
● NO IFs 
● Border cases handled on demand 
● More declarative types 
● Highlight business code 
● Easy to create 
● More reusable code
Thank You! 
Christophe Marchal | Software Architect
1 of 47

Recommended

1271215439 597183 by
1271215439 5971831271215439 597183
1271215439 597183vinod kumar
563 views2 slides
F# for BLOBA, by brandon d'imperio by
F# for BLOBA, by brandon d'imperioF# for BLOBA, by brandon d'imperio
F# for BLOBA, by brandon d'imperioMaslowB
1.1K views23 slides
Bba105 by
Bba105Bba105
Bba105Rajesh Kumar Singh
95 views2 slides
Unlocking the Magic of Monads with Java 8 by
Unlocking the Magic of Monads with Java 8Unlocking the Magic of Monads with Java 8
Unlocking the Magic of Monads with Java 8JavaDayUA
938 views72 slides
Monadic Java by
Monadic JavaMonadic Java
Monadic JavaCodemotion
1.2K views52 slides

More Related Content

Viewers also liked

Functional programming techniques in regular JavaScript by
Functional programming techniques in regular JavaScriptFunctional programming techniques in regular JavaScript
Functional programming techniques in regular JavaScriptPavel Klimiankou
722 views101 slides
[FT-11][ltchen] A Tale of Two Monads by
[FT-11][ltchen] A Tale of Two Monads[FT-11][ltchen] A Tale of Two Monads
[FT-11][ltchen] A Tale of Two MonadsFunctional Thursday
690 views29 slides
Monadic Java by
Monadic JavaMonadic Java
Monadic JavaMario Fusco
65.9K views73 slides
Advanced Production Debugging by
Advanced Production DebuggingAdvanced Production Debugging
Advanced Production DebuggingTakipi
135.6K views35 slides
Project Jigsaw in JDK 9: Modularity Comes To Java by
Project Jigsaw in JDK 9: Modularity Comes To JavaProject Jigsaw in JDK 9: Modularity Comes To Java
Project Jigsaw in JDK 9: Modularity Comes To JavaC4Media
38.4K views59 slides
Java 9: The (G1) GC Awakens! by
Java 9: The (G1) GC Awakens!Java 9: The (G1) GC Awakens!
Java 9: The (G1) GC Awakens!Monica Beckwith
39.7K views99 slides

Viewers also liked(10)

Functional programming techniques in regular JavaScript by Pavel Klimiankou
Functional programming techniques in regular JavaScriptFunctional programming techniques in regular JavaScript
Functional programming techniques in regular JavaScript
Pavel Klimiankou722 views
Monadic Java by Mario Fusco
Monadic JavaMonadic Java
Monadic Java
Mario Fusco65.9K views
Advanced Production Debugging by Takipi
Advanced Production DebuggingAdvanced Production Debugging
Advanced Production Debugging
Takipi135.6K views
Project Jigsaw in JDK 9: Modularity Comes To Java by C4Media
Project Jigsaw in JDK 9: Modularity Comes To JavaProject Jigsaw in JDK 9: Modularity Comes To Java
Project Jigsaw in JDK 9: Modularity Comes To Java
C4Media38.4K views
Java 9: The (G1) GC Awakens! by Monica Beckwith
Java 9: The (G1) GC Awakens!Java 9: The (G1) GC Awakens!
Java 9: The (G1) GC Awakens!
Monica Beckwith39.7K views
10 SQL Tricks that You Didn't Think Were Possible by Lukas Eder
10 SQL Tricks that You Didn't Think Were Possible10 SQL Tricks that You Didn't Think Were Possible
10 SQL Tricks that You Didn't Think Were Possible
Lukas Eder2.1M views
Microservices + Oracle: A Bright Future by Kelly Goetsch
Microservices + Oracle: A Bright FutureMicroservices + Oracle: A Bright Future
Microservices + Oracle: A Bright Future
Kelly Goetsch74.7K views

Similar to Monads in practice

Try the monad! by
Try the monad!Try the monad!
Try the monad!Luis Muniz
1K views34 slides
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#... by
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...PROIDEA
61 views38 slides
Railway Orientated Programming In C# by
Railway Orientated Programming In C#Railway Orientated Programming In C#
Railway Orientated Programming In C#Tama000
1.4K views59 slides
Improving Code Quality Through Effective Review Process by
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review ProcessDr. Syed Hassan Amin
721 views32 slides
London F-Sharp User Group : Don Syme on F# - 09/09/2010 by
London F-Sharp User Group : Don Syme on F# - 09/09/2010London F-Sharp User Group : Don Syme on F# - 09/09/2010
London F-Sharp User Group : Don Syme on F# - 09/09/2010Skills Matter
351 views81 slides
24 common mistakes in go (gotchas) and how to avoid them by
24 common mistakes in go (gotchas) and how to avoid them24 common mistakes in go (gotchas) and how to avoid them
24 common mistakes in go (gotchas) and how to avoid themKaty Slemon
62 views55 slides

Similar to Monads in practice(20)

[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#... by PROIDEA
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...
PROIDEA61 views
Railway Orientated Programming In C# by Tama000
Railway Orientated Programming In C#Railway Orientated Programming In C#
Railway Orientated Programming In C#
Tama0001.4K views
Improving Code Quality Through Effective Review Process by Dr. Syed Hassan Amin
Improving Code Quality Through Effective  Review ProcessImproving Code Quality Through Effective  Review Process
Improving Code Quality Through Effective Review Process
London F-Sharp User Group : Don Syme on F# - 09/09/2010 by Skills Matter
London F-Sharp User Group : Don Syme on F# - 09/09/2010London F-Sharp User Group : Don Syme on F# - 09/09/2010
London F-Sharp User Group : Don Syme on F# - 09/09/2010
Skills Matter351 views
24 common mistakes in go (gotchas) and how to avoid them by Katy Slemon
24 common mistakes in go (gotchas) and how to avoid them24 common mistakes in go (gotchas) and how to avoid them
24 common mistakes in go (gotchas) and how to avoid them
Katy Slemon62 views
When e-commerce meets Symfony by Marc Morera
When e-commerce meets SymfonyWhen e-commerce meets Symfony
When e-commerce meets Symfony
Marc Morera1.3K views
DDD beyond the infamous repository pattern - GeeCon Prague 2018 by Cyrille Martraire
DDD beyond the infamous repository pattern - GeeCon Prague 2018DDD beyond the infamous repository pattern - GeeCon Prague 2018
DDD beyond the infamous repository pattern - GeeCon Prague 2018
Stop fearing legacy code by Yaki Koren
Stop fearing legacy codeStop fearing legacy code
Stop fearing legacy code
Yaki Koren99 views
Problem solving by ho94949
Problem solvingProblem solving
Problem solving
ho94949405 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software385 views
No more dead kittens - Clean Code by Yves Hoppe
No more dead kittens - Clean CodeNo more dead kittens - Clean Code
No more dead kittens - Clean Code
Yves Hoppe500 views
Code Smells and Its type (With Example) by Anshul Vinayak
Code Smells and Its type (With Example)Code Smells and Its type (With Example)
Code Smells and Its type (With Example)
Anshul Vinayak8.6K views

More from Christophe Marchal

Elasticsearch avoiding hotspots by
Elasticsearch  avoiding hotspotsElasticsearch  avoiding hotspots
Elasticsearch avoiding hotspotsChristophe Marchal
1.9K views16 slides
Performance by
PerformancePerformance
PerformanceChristophe Marchal
425 views17 slides
Alluxio by
AlluxioAlluxio
AlluxioChristophe Marchal
373 views14 slides
Elasticsearch cluster deep dive by
Elasticsearch  cluster deep diveElasticsearch  cluster deep dive
Elasticsearch cluster deep diveChristophe Marchal
1.2K views46 slides
Elasticsearch by
ElasticsearchElasticsearch
ElasticsearchChristophe Marchal
285 views42 slides
Reactive programming with Rxjava by
Reactive programming with RxjavaReactive programming with Rxjava
Reactive programming with RxjavaChristophe Marchal
1.2K views76 slides

More from Christophe Marchal(20)

Microservices Architecture: Nirvana or Nightmare by Christophe Marchal
Microservices Architecture: Nirvana or NightmareMicroservices Architecture: Nirvana or Nightmare
Microservices Architecture: Nirvana or Nightmare
Christophe Marchal1.5K views
Aws, play! couch db scaling soa in the cloud by Christophe Marchal
Aws, play! couch db  scaling soa in the cloudAws, play! couch db  scaling soa in the cloud
Aws, play! couch db scaling soa in the cloud
Christophe Marchal820 views
Devops e a nova cultura - TDC Florianopolis 2015 by Christophe Marchal
Devops e a nova cultura - TDC Florianopolis 2015Devops e a nova cultura - TDC Florianopolis 2015
Devops e a nova cultura - TDC Florianopolis 2015
Christophe Marchal753 views
Productivity and scalability with Play and Scala by Christophe Marchal
Productivity and scalability with Play and ScalaProductivity and scalability with Play and Scala
Productivity and scalability with Play and Scala
Christophe Marchal345 views
Integration with hdfs using WebDFS and NFS by Christophe Marchal
Integration with hdfs using WebDFS and NFSIntegration with hdfs using WebDFS and NFS
Integration with hdfs using WebDFS and NFS
Christophe Marchal1.5K views

Recently uploaded

FIMA 2023 Neo4j & FS - Entity Resolution.pptx by
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptxNeo4j
17 views26 slides
Benefits in Software Development by
Benefits in Software DevelopmentBenefits in Software Development
Benefits in Software DevelopmentJohn Valentino
5 views15 slides
Introduction to Git Source Control by
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source ControlJohn Valentino
7 views18 slides
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... by
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...sparkfabrik
8 views46 slides
Top-5-production-devconMunich-2023-v2.pptx by
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptxTier1 app
6 views42 slides
The Path to DevOps by
The Path to DevOpsThe Path to DevOps
The Path to DevOpsJohn Valentino
5 views6 slides

Recently uploaded(20)

FIMA 2023 Neo4j & FS - Entity Resolution.pptx by Neo4j
FIMA 2023 Neo4j & FS - Entity Resolution.pptxFIMA 2023 Neo4j & FS - Entity Resolution.pptx
FIMA 2023 Neo4j & FS - Entity Resolution.pptx
Neo4j17 views
Introduction to Git Source Control by John Valentino
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source Control
John Valentino7 views
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... by sparkfabrik
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
sparkfabrik8 views
Top-5-production-devconMunich-2023-v2.pptx by Tier1 app
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptx
Tier1 app6 views
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... by TomHalpin9
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
TomHalpin96 views
FOSSLight Community Day 2023-11-30 by Shane Coughlan
FOSSLight Community Day 2023-11-30FOSSLight Community Day 2023-11-30
FOSSLight Community Day 2023-11-30
Shane Coughlan6 views
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok16 views
Airline Booking Software by SharmiMehta
Airline Booking SoftwareAirline Booking Software
Airline Booking Software
SharmiMehta9 views
Bootstrapping vs Venture Capital.pptx by Zeljko Svedic
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic15 views
How Workforce Management Software Empowers SMEs | TraQSuite by TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuite
TraQSuite6 views
JioEngage_Presentation.pptx by admin125455
JioEngage_Presentation.pptxJioEngage_Presentation.pptx
JioEngage_Presentation.pptx
admin1254558 views

Monads in practice