Monads Explained
for OOP Developers
NextBuild Eindhoven | September 29 | 2018
Mikhail Shilkov
Monads Explained for OOP Developers
MONAD
MONOID
CATEGORY
ENDOFUNCTORS
“
“
Douglas Crockford,
who found Good Partsin
Javascript
Monads are cursed — once you
understand monads for yourself
you lose the ability to explain them
to others
“
“
Tomas Petricek,
The Alan Turing Institute
http://tomasp.net/academic/pa
pers/monads/monads-
programming.pdf
Learning monads and writing a
monad tutorial has also become
an important milestone in
learning about theory of
functional programming
Monads Explained for OOP Developers
Monads Explained for OOP Developers
// Type annotation
func: TypeA -> TypeB
// Static methods
static class Mapper {
static ClassB func(ClassA a) { ... }
}
// Instance methods
class ClassA {
ClassB func() { ... }
}
class Speaker {
Talk nextTalk() { ... }
}
class Talk {
Conference getConference() { ... }
}
class Conference {
City getCity() { ... }
}
static City nextTalkCity(Speaker speaker)
{
Talk talk = speaker.nextTalk();
Conference conf = talk.getConference();
City city = conf.getCity();
return city;
}
City nextTalkCity Speaker
nextTalk
getConference
getCity
Monads Explained for OOP Developers
NULL
class Speaker {
Talk nextTalk() { ... }
}
class Talk {
Conference getConference() { ... }
}
class Conference {
City getCity() { ... }
}
Speaker
Nullable<Talk> nextTalk
Talk
Nullable<Conference> getConference
Conference
Nullable<City> getCity
Nullable<City> nextTalkCity Speaker
Talk? nextTalk
Conference? getConference
City? getCity
Nullable<City> nextTalkCity Speaker
Talk? nextTalk
Conference? getConference
City? getCity
Nullable<City> nextTalkCity Speaker
nextTalk
getConference
getCity
Speaker
Optional<Talk> nextTalk
Talk
Optional<Conference> getConference
Conference
Optional<City> getCity
Optional<City> nextTalkCity
Speaker
nextTalk
getConference
getCity
Optional<City> nextTalkCity Speaker
nextTalk
getConference
getCity
Monads Explained for OOP Developers
Speaker
List<Talk> getTalks
Talk
List<Conference> getConferences
Conference
List<City> getCities
List<City> allCitiesToVisit Speaker
List<City>
Talk getTalks
Conference getConferences
City getCities
List<City> allCitiesToVisit Speaker
getTalks
getConferences
getCities
List<City> allCitiesToVisit Speaker
getTalks
getConferences
getCities
List<City> allCitiesToVisit Speaker
getTalks
getConferences
getCities
List<City> allCitiesToVisit Speaker
getTalks
getConferences
getCities
Monads Explained for OOP Developers
Speaker
Task<Talk> nextTalk
Talk
Task<Conference> getConference
Conference
Task<City> getCity
Task<City> nextTalkCity Speaker
nextTalk
getConference
getCity
Task<City> nextTalkCity Speaker
nextTalk
getConference
getCity
CompletableFuture<City> nextTalkCity
Speaker
nextTalk
getConference
getCity
CompletableFuture<City> nextTalkCity
Speaker
nextTalk
getConference
getCity
PATTERN
nextTalk
getConference
getCity // Optional<T>
getTalks
getConferences
getCities // List<T>
nextTalk
getConference
getCity // CompletableFuture<T>
WorkflowThatReturns<T>
WorkflowThatReturns<U> addStep
T WorkflowThatReturns<U>
WorkflowThatReturns<Phone> workflow Speaker
nextTalk
getConference
getCity
Monad<T>
Monad<U> bind T Monad<U>
// or alternatively
Monad<T>
Monad<U> apply T U
Monad<U> unwrap Monad<Monad<U>>
Optional<T>
// ... constructors go here
Optional<U> flatMap T Optional<U> func
func
Optional
Enumerable
IEnumerable<U> SelectMany
IEnumerable<T>
T IEnumerable<U> func
func
CompletableFuture
CompletableFuture<U> thenCompose
T CompletableFuture<U>> func
// Some black magic happens here,
// but it works!!!
WORKFLOW
Talk talk
talk
talk
talk
async
talk await
await talk
await talk
MONADS
nextTalkCity async
let! nextTalk
let! getConference
let! getCity
nextTalkCity option
let! nextTalk
let! getConference
let! getCity
actor
let!
return!
OptionBuilder
Return
Bind func
func
MONAD
• Pattern
• Generic Container
• Workflow Builder
“
“
John De Goes,
who knows what
Monads are
Monads are virtual machines for
expressing sequential, dependent
computation, where the instruction
set of a VM is given by the structure
of the monad's constructors
Monads
explained in
C#
Monads
explained in
Kotlin
F#P Eindhoven
Meetup
@MikhailShilkov
https://mikhail.io

More Related Content

PPTX
Monads Explained for OOP Developers
PPTX
Monads Explained for OOP Developers - Mikhail Shilkov - Codemotion Rome 2018
PDF
ITCamp 2013 - Adam Granicz - Developing for W8 with F# and WebSharper
PDF
The Dynamic Language is not Enough
PDF
Data-First Online Functional Programming with F# (Adam Granicz)
PPT
ActiveTM - A Topic Maps - Object Mapper
PDF
Microservices Chaos Testing at Jet
PDF
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Monads Explained for OOP Developers
Monads Explained for OOP Developers - Mikhail Shilkov - Codemotion Rome 2018
ITCamp 2013 - Adam Granicz - Developing for W8 with F# and WebSharper
The Dynamic Language is not Enough
Data-First Online Functional Programming with F# (Adam Granicz)
ActiveTM - A Topic Maps - Object Mapper
Microservices Chaos Testing at Jet
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...

Similar to Monads Explained for OOP Developers (20)

PPTX
TechDaysNL 2015 - F# for C# Developers
PDF
Enabling Data Scientists to easily create and own Kafka Consumers | Stefan Kr...
PDF
Enabling Data Scientists to easily create and own Kafka Consumers
PDF
Legacy is Good
PDF
MLflow with R
PDF
Refactoring for Software Architecture Smells - International Workshop on Refa...
PDF
DDD on example of Symfony (SfCampUA14)
PPTX
Patterns and practices for real-world event-driven microservices by Rachel Re...
PPTX
Patterns and practices for real-world event-driven microservices
PPT
Visual Studio .NET2010
PDF
Architectural Patterns in Building Modular Domain Models
PDF
Protocol-Oriented Programming in Swift
PDF
Rethink your architecture - Marten Deinum
PDF
Modern Release Engineering in a Nutshell - Why Researchers should Care!
PDF
LINEデリマでのElasticsearchの運用と監視の話
PDF
Object Orientation.pdf
PPTX
Willow, the interaction tour by Maxi Tabacman
PDF
Engineering Efficiency in LINE
PDF
Programming Languages: some news for the last N years
PDF
Patterns & Practices for Cloud-based Microservices
TechDaysNL 2015 - F# for C# Developers
Enabling Data Scientists to easily create and own Kafka Consumers | Stefan Kr...
Enabling Data Scientists to easily create and own Kafka Consumers
Legacy is Good
MLflow with R
Refactoring for Software Architecture Smells - International Workshop on Refa...
DDD on example of Symfony (SfCampUA14)
Patterns and practices for real-world event-driven microservices by Rachel Re...
Patterns and practices for real-world event-driven microservices
Visual Studio .NET2010
Architectural Patterns in Building Modular Domain Models
Protocol-Oriented Programming in Swift
Rethink your architecture - Marten Deinum
Modern Release Engineering in a Nutshell - Why Researchers should Care!
LINEデリマでのElasticsearchの運用と監視の話
Object Orientation.pdf
Willow, the interaction tour by Maxi Tabacman
Engineering Efficiency in LINE
Programming Languages: some news for the last N years
Patterns & Practices for Cloud-based Microservices
Ad

More from ☁️ Mikhail Shilkov (8)

PDF
Performance Tales of Serverless - CloudNative London 2018
PPTX
Performance Tales of Serverless
PPTX
Azure F#unctions
PDF
Azure F#unctions
PPTX
Event Driven Applications in F#
PDF
Why Learn F# and Functional Programming
PDF
The taste of F#
PDF
Introduction of Functional Programming
Performance Tales of Serverless - CloudNative London 2018
Performance Tales of Serverless
Azure F#unctions
Azure F#unctions
Event Driven Applications in F#
Why Learn F# and Functional Programming
The taste of F#
Introduction of Functional Programming
Ad

Recently uploaded (20)

PDF
STKI Israel Market Study 2025 version august
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PDF
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
PPTX
Benefits of Physical activity for teenagers.pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PDF
The influence of sentiment analysis in enhancing early warning system model f...
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PPTX
The various Industrial Revolutions .pptx
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
Architecture types and enterprise applications.pdf
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
Microsoft Excel 365/2024 Beginner's training
DOCX
search engine optimization ppt fir known well about this
PDF
A proposed approach for plagiarism detection in Myanmar Unicode text
PPTX
Configure Apache Mutual Authentication
STKI Israel Market Study 2025 version august
Module 1.ppt Iot fundamentals and Architecture
UiPath Agentic Automation session 1: RPA to Agents
OpenACC and Open Hackathons Monthly Highlights July 2025
A review of recent deep learning applications in wood surface defect identifi...
Convolutional neural network based encoder-decoder for efficient real-time ob...
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
Benefits of Physical activity for teenagers.pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Credit Without Borders: AI and Financial Inclusion in Bangladesh
The influence of sentiment analysis in enhancing early warning system model f...
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
The various Industrial Revolutions .pptx
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Architecture types and enterprise applications.pdf
Final SEM Unit 1 for mit wpu at pune .pptx
Microsoft Excel 365/2024 Beginner's training
search engine optimization ppt fir known well about this
A proposed approach for plagiarism detection in Myanmar Unicode text
Configure Apache Mutual Authentication

Monads Explained for OOP Developers