SlideShare une entreprise Scribd logo
1  sur  24
Functors,Applicatives and MonadsFunctors,Applicatives and Monads
Pallavi Singh
Software Consultant
Knoldus Software LLP
Objectives:
 Functors
 Applicatives
 Monads
 Demo
Objectives:
 Functors
 Applicatives
 Monads
 Demo
Problem :
We have a simple value
We apply a function to it
Lets extend it ,
the value can be in a context,
Now when we apply a function
to this value,we get results
depending on the context.
Problem :
We have a simple value
We apply a function to it
Lets extend it ,
the value can be in a context,
Now when we apply a function
to this value,we get results
depending on the context.
Image Source : http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
Functors
When a value is wrapped in a context, you
can’t apply a normal function to the value.
We need a map. The map knows how to
apply functions to values that are wrapped in
a context.
Functors
When a value is wrapped in a context, you
can’t apply a normal function to the value.
We need a map. The map knows how to
apply functions to values that are wrapped in
a context.
Image Source :
http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
Functors
Definition : Functor is a type class. A Functor is
any data type that defines how map applies to it.
Speaking in-formally you apply a function to a
wrapped value using map. The map knows how to
apply the function.
Functors
Definition : Functor is a type class. A Functor is
any data type that defines how map applies to it.
Speaking in-formally you apply a function to a
wrapped value using map. The map knows how to
apply the function.
Functors
We have a Constructor C[_] and two types A and B,we
want to apply functions of type C[A]=>C[B], so we need
adequate transformations
( A=>B ) => ( C[A]=>C[B] )
And we need to define a map
def map[A,B](A=>B):(F[A]=>F[B] )
Functors
We have a Constructor C[_] and two types A and B,we
want to apply functions of type C[A]=>C[B], so we need
adequate transformations
( A=>B ) => ( C[A]=>C[B] )
And we need to define a map
def map[A,B](A=>B):(F[A]=>F[B] )
Functors
Example: Options , Streams
Object OptionFunctor extends Functor[Option] {
def map[A, B](f: A B): Option[A] Option[B] = option option map f⇒ ⇒ ⇒
}
Functors
Example: Options , Streams
Object OptionFunctor extends Functor[Option] {
def map[A, B](f: A B): Option[A] Option[B] = option option map f⇒ ⇒ ⇒
}
Problem :
Given a function
what happens when you apply a function to
another function , we have another function.
Functions are functors too ! A map on a function is
function composition.
Problem :
Given a function
what happens when you apply a function to
another function , we have another function.
Functions are functors too ! A map on a function is
function composition.
Image Source :
http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
Problem :
We have a value wrapped in context
And functions are wrapped in a context too!
Problem :
We have a value wrapped in context
And functions are wrapped in a context too!
Image Source :
http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
Applicatives
When a value and function both are wrapped in a
context. We can’t apply it as we apply a simple function.
We need an apply. It knows how to apply a function
wrapped in a context to a value wrapped in a context.
56rt67
Applicatives
When a value and function both are wrapped in a
context. We can’t apply it as we apply a simple function.
We need an apply. It knows how to apply a function
wrapped in a context to a value wrapped in a context.
56rt67
Image Source :
http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
Applicatives
Def : Applicative is typeclass. Applicative is any data type
that defines how apply applies to it.
Apply takes a functor that has a function in it and another
functor and extracts that function from the first functor
and then maps it over the second one.
Speaking in-formally you apply a function wrapped in
context to a value wrapped in context.
Applicatives
Def : Applicative is typeclass. Applicative is any data type
that defines how apply applies to it.
Apply takes a functor that has a function in it and another
functor and extracts that function from the first functor
and then maps it over the second one.
Speaking in-formally you apply a function wrapped in
context to a value wrapped in context.
Image Source :
http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
Applicatives
We have a Constructor C[_] and two types A and B, we
want to apply functions of type C[A]=>C[B],so we need
adequate transformations
(C[A=>B] ) => ( C[A]=>C[B] )
And we need to define a apply
def apply[A,B](F[A=>B]):(F[A]=>F[B] )
Applicatives
We have a Constructor C[_] and two types A and B, we
want to apply functions of type C[A]=>C[B],so we need
adequate transformations
(C[A=>B] ) => ( C[A]=>C[B] )
And we need to define a apply
def apply[A,B](F[A=>B]):(F[A]=>F[B] )
Image Source :
http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
Problem :
Given a function
what happens if we feed it a
wrapped value?
Problem :
Given a function
what happens if we feed it a
wrapped value?
Image Source :
http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
Monads
Monads apply a
function that
returns a
wrapped value to
a wrapped value.
Monads
Monads apply a
function that
returns a
wrapped value to
a wrapped value.
Image Source :
http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
Image Source :
http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
Monads
Definition: Monad is a type class. A monad is a
data type that implements the flatMap.
Speaking in-formally you apply a function that
returns a wrapped value, to a wrapped value.
Monads
Definition: Monad is a type class. A monad is a
data type that implements the flatMap.
Speaking in-formally you apply a function that
returns a wrapped value, to a wrapped value.
Monads
We have a Constructor C[_] and two types A and
B,we want to apply functions of type C[A]=>C[B],
so we need adequate transformations
( A=>C[B] ) => ( C[A]=>C[B] )
And we need to define a flatMap
def flatMap[A,B](A=>F[B]):(F[A]=>F[B] )
Monads
We have a Constructor C[_] and two types A and
B,we want to apply functions of type C[A]=>C[B],
so we need adequate transformations
( A=>C[B] ) => ( C[A]=>C[B] )
And we need to define a flatMap
def flatMap[A,B](A=>F[B]):(F[A]=>F[B] )
Monads
Example: List , Set , Option and Future all
are Monads
Future is a wrapper over some asynchronous operation.
Once the future has been completed you can do
whatever it is you need to do with its result.
Monads
Example: List , Set , Option and Future all
are Monads
Future is a wrapper over some asynchronous operation.
Once the future has been completed you can do
whatever it is you need to do with its result.
Difference b/w Monad and Monoids ?
Monoid : Given a type T, a binary operation Op:(T,T)=>T
and instance Zero:T then the triple(T, Op , Zero) is called
a Monoid if it has the following properties: Neutral
Element and Associativity.
Monad instance simply wraps the value of type A within
the given context and expose a certain set of methods to
operate on them,
Monoid instance already knows how to combine these
values of type A within the given context.
Difference b/w Monad and Monoids ?
Monoid : Given a type T, a binary operation Op:(T,T)=>T
and instance Zero:T then the triple(T, Op , Zero) is called
a Monoid if it has the following properties: Neutral
Element and Associativity.
Monad instance simply wraps the value of type A within
the given context and expose a certain set of methods to
operate on them,
Monoid instance already knows how to combine these
values of type A within the given context.
Are Monads powerful than
Applicatives?
Applicatives and monads both model running
computations in sequence. But Monads are more
powerful because with applicatives you can sequence the
computations, but monads allow you to sequence
computations with the additional property that the result
of subsequent computations can depend on the result of
previous computation.
Are Monads powerful than
Applicatives?
Applicatives and monads both model running
computations in sequence. But Monads are more
powerful because with applicatives you can sequence the
computations, but monads allow you to sequence
computations with the additional property that the result
of subsequent computations can depend on the result of
previous computation.
Demo
https://github.com/knoldus/functors-applicatives-monads
Demo
https://github.com/knoldus/functors-applicatives-monads
QuestionsQuestions
References
 http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
 http://www.smartjava.org/content/scalaz-features-everyday-usage-part-1-typeclasses-
and-scala-extensions
 http://eed3si9n.com/learning-scalaz/Applicative.html
 https://thedet.wordpress.com/2013/02/11/functors-in-images/
 https://thedet.wordpress.com/2012/05/20/functors-monads-applicatives-playing-with-
map-functor/
References
 http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
 http://www.smartjava.org/content/scalaz-features-everyday-usage-part-1-typeclasses-
and-scala-extensions
 http://eed3si9n.com/learning-scalaz/Applicative.html
 https://thedet.wordpress.com/2013/02/11/functors-in-images/
 https://thedet.wordpress.com/2012/05/20/functors-monads-applicatives-playing-with-
map-functor/
Thank YouThank You

Contenu connexe

Tendances

Sequence and Traverse - Part 1
Sequence and Traverse - Part 1Sequence and Traverse - Part 1
Sequence and Traverse - Part 1Philip Schwarz
 
The Functional Programming Triad of Map, Filter and Fold
The Functional Programming Triad of Map, Filter and FoldThe Functional Programming Triad of Map, Filter and Fold
The Functional Programming Triad of Map, Filter and FoldPhilip Schwarz
 
Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Philip Schwarz
 
Functor, Apply, Applicative And Monad
Functor, Apply, Applicative And MonadFunctor, Apply, Applicative And Monad
Functor, Apply, Applicative And MonadOliver Daff
 
Writer Monad for logging execution of functions
Writer Monad for logging execution of functionsWriter Monad for logging execution of functions
Writer Monad for logging execution of functionsPhilip Schwarz
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8Victor Rentea
 
Running Free with the Monads
Running Free with the MonadsRunning Free with the Monads
Running Free with the Monadskenbot
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...Philip Schwarz
 
Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python Jean Carlo Machado
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithVictor Rentea
 
Taking your side effects aside
Taking your side effects asideTaking your side effects aside
Taking your side effects aside💡 Tomasz Kogut
 
Design functional solutions in Java, a practical example
Design functional solutions in Java, a practical exampleDesign functional solutions in Java, a practical example
Design functional solutions in Java, a practical exampleMarian Wamsiedel
 
Refactoring Functional Type Classes
Refactoring Functional Type ClassesRefactoring Functional Type Classes
Refactoring Functional Type ClassesJohn De Goes
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...Philip Schwarz
 

Tendances (20)

Sequence and Traverse - Part 1
Sequence and Traverse - Part 1Sequence and Traverse - Part 1
Sequence and Traverse - Part 1
 
The Functional Programming Triad of Map, Filter and Fold
The Functional Programming Triad of Map, Filter and FoldThe Functional Programming Triad of Map, Filter and Fold
The Functional Programming Triad of Map, Filter and Fold
 
Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Sequence and Traverse - Part 2
Sequence and Traverse - Part 2
 
Functor, Apply, Applicative And Monad
Functor, Apply, Applicative And MonadFunctor, Apply, Applicative And Monad
Functor, Apply, Applicative And Monad
 
Writer Monad for logging execution of functions
Writer Monad for logging execution of functionsWriter Monad for logging execution of functions
Writer Monad for logging execution of functions
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8
 
Running Free with the Monads
Running Free with the MonadsRunning Free with the Monads
Running Free with the Monads
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...The aggregate function - from sequential and parallel folds to parallel aggre...
The aggregate function - from sequential and parallel folds to parallel aggre...
 
Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python Domain Driven Design Made Functional with Python
Domain Driven Design Made Functional with Python
 
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a Monolith
 
Taking your side effects aside
Taking your side effects asideTaking your side effects aside
Taking your side effects aside
 
polymorphism
polymorphism polymorphism
polymorphism
 
Design functional solutions in Java, a practical example
Design functional solutions in Java, a practical exampleDesign functional solutions in Java, a practical example
Design functional solutions in Java, a practical example
 
Refactoring Functional Type Classes
Refactoring Functional Type ClassesRefactoring Functional Type Classes
Refactoring Functional Type Classes
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
 

En vedette

Domain-driven design
Domain-driven designDomain-driven design
Domain-driven designKnoldus Inc.
 
Go for the Money - JSR 354
Go for the Money - JSR 354Go for the Money - JSR 354
Go for the Money - JSR 354Anatole Tresch
 
Introduction to Option monad in Scala
Introduction to Option monad in ScalaIntroduction to Option monad in Scala
Introduction to Option monad in ScalaJan Krag
 
Introduction to Scala JS
Introduction to Scala JSIntroduction to Scala JS
Introduction to Scala JSKnoldus Inc.
 
Drilling the Async Library
Drilling the Async LibraryDrilling the Async Library
Drilling the Async LibraryKnoldus Inc.
 
Getting Started With AureliaJs
Getting Started With AureliaJsGetting Started With AureliaJs
Getting Started With AureliaJsKnoldus Inc.
 
String interpolation
String interpolationString interpolation
String interpolationKnoldus Inc.
 
Mailchimp and Mandrill - The ‘Hominidae’ kingdom
Mailchimp and Mandrill - The ‘Hominidae’ kingdomMailchimp and Mandrill - The ‘Hominidae’ kingdom
Mailchimp and Mandrill - The ‘Hominidae’ kingdomKnoldus Inc.
 
Realm Mobile Database - An Introduction
Realm Mobile Database - An IntroductionRealm Mobile Database - An Introduction
Realm Mobile Database - An IntroductionKnoldus Inc.
 
Shapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaShapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaKnoldus Inc.
 
An Introduction to Quill
An Introduction to QuillAn Introduction to Quill
An Introduction to QuillKnoldus Inc.
 
Introduction to Scala Macros
Introduction to Scala MacrosIntroduction to Scala Macros
Introduction to Scala MacrosKnoldus Inc.
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8Knoldus Inc.
 
Mandrill Templates
Mandrill TemplatesMandrill Templates
Mandrill TemplatesKnoldus Inc.
 
Introduction to Knockout Js
Introduction to Knockout JsIntroduction to Knockout Js
Introduction to Knockout JsKnoldus Inc.
 
ANTLR4 and its testing
ANTLR4 and its testingANTLR4 and its testing
ANTLR4 and its testingKnoldus Inc.
 
Effective way to code in Scala
Effective way to code in ScalaEffective way to code in Scala
Effective way to code in ScalaKnoldus Inc.
 
Introduction to ScalaZ
Introduction to ScalaZIntroduction to ScalaZ
Introduction to ScalaZKnoldus Inc.
 

En vedette (20)

Domain-driven design
Domain-driven designDomain-driven design
Domain-driven design
 
Go for the Money - JSR 354
Go for the Money - JSR 354Go for the Money - JSR 354
Go for the Money - JSR 354
 
Introduction to Option monad in Scala
Introduction to Option monad in ScalaIntroduction to Option monad in Scala
Introduction to Option monad in Scala
 
Introduction to Scala JS
Introduction to Scala JSIntroduction to Scala JS
Introduction to Scala JS
 
Drilling the Async Library
Drilling the Async LibraryDrilling the Async Library
Drilling the Async Library
 
Akka streams
Akka streamsAkka streams
Akka streams
 
Getting Started With AureliaJs
Getting Started With AureliaJsGetting Started With AureliaJs
Getting Started With AureliaJs
 
String interpolation
String interpolationString interpolation
String interpolation
 
Mailchimp and Mandrill - The ‘Hominidae’ kingdom
Mailchimp and Mandrill - The ‘Hominidae’ kingdomMailchimp and Mandrill - The ‘Hominidae’ kingdom
Mailchimp and Mandrill - The ‘Hominidae’ kingdom
 
Realm Mobile Database - An Introduction
Realm Mobile Database - An IntroductionRealm Mobile Database - An Introduction
Realm Mobile Database - An Introduction
 
Kanban
KanbanKanban
Kanban
 
Shapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaShapeless- Generic programming for Scala
Shapeless- Generic programming for Scala
 
An Introduction to Quill
An Introduction to QuillAn Introduction to Quill
An Introduction to Quill
 
Introduction to Scala Macros
Introduction to Scala MacrosIntroduction to Scala Macros
Introduction to Scala Macros
 
Introduction to Java 8
Introduction to Java 8Introduction to Java 8
Introduction to Java 8
 
Mandrill Templates
Mandrill TemplatesMandrill Templates
Mandrill Templates
 
Introduction to Knockout Js
Introduction to Knockout JsIntroduction to Knockout Js
Introduction to Knockout Js
 
ANTLR4 and its testing
ANTLR4 and its testingANTLR4 and its testing
ANTLR4 and its testing
 
Effective way to code in Scala
Effective way to code in ScalaEffective way to code in Scala
Effective way to code in Scala
 
Introduction to ScalaZ
Introduction to ScalaZIntroduction to ScalaZ
Introduction to ScalaZ
 

Similaire à Functors, Applicatives and Monads In Scala

C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]Rome468
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxvrickens
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures topu93
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture topu93
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdfprasnt1
 
How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1Taisuke Oe
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Akhil Mittal
 
OOP-Advanced Programming with c++
OOP-Advanced Programming with c++OOP-Advanced Programming with c++
OOP-Advanced Programming with c++Mohamed Essam
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsakreyi
 
How to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooksHow to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooksKaty Slemon
 
C basic questions&ansrs by shiva kumar kella
C basic questions&ansrs by shiva kumar kellaC basic questions&ansrs by shiva kumar kella
C basic questions&ansrs by shiva kumar kellaManoj Kumar kothagulla
 
Tcs NQTExam technical questions
Tcs NQTExam technical questionsTcs NQTExam technical questions
Tcs NQTExam technical questionsAniketBhandare2
 
Introduction to C++ Programming
Introduction to C++ ProgrammingIntroduction to C++ Programming
Introduction to C++ ProgrammingPreeti Kashyap
 
C questions
C questionsC questions
C questionsparm112
 
Book management system
Book management systemBook management system
Book management systemSHARDA SHARAN
 
Architectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsArchitectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsDebasish Ghosh
 

Similaire à Functors, Applicatives and Monads In Scala (20)

C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture
 
Functions2.pdf
Functions2.pdfFunctions2.pdf
Functions2.pdf
 
How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1
 
C++ interview question
C++ interview questionC++ interview question
C++ interview question
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
 
C++
C++C++
C++
 
OOP-Advanced Programming with c++
OOP-Advanced Programming with c++OOP-Advanced Programming with c++
OOP-Advanced Programming with c++
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
java tr.docx
java tr.docxjava tr.docx
java tr.docx
 
How to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooksHow to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooks
 
C basic questions&ansrs by shiva kumar kella
C basic questions&ansrs by shiva kumar kellaC basic questions&ansrs by shiva kumar kella
C basic questions&ansrs by shiva kumar kella
 
Tcs NQTExam technical questions
Tcs NQTExam technical questionsTcs NQTExam technical questions
Tcs NQTExam technical questions
 
Introduction to C++ Programming
Introduction to C++ ProgrammingIntroduction to C++ Programming
Introduction to C++ Programming
 
C questions
C questionsC questions
C questions
 
Book management system
Book management systemBook management system
Book management system
 
Oo ps exam answer2
Oo ps exam answer2Oo ps exam answer2
Oo ps exam answer2
 
Architectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsArchitectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain Models
 

Plus de Knoldus Inc.

Authentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxAuthentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxKnoldus Inc.
 
OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)Knoldus Inc.
 
Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxKnoldus Inc.
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingKnoldus Inc.
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionKnoldus Inc.
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxKnoldus Inc.
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptxKnoldus Inc.
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfKnoldus Inc.
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxKnoldus Inc.
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingKnoldus Inc.
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesKnoldus Inc.
 
Introduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxIntroduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxKnoldus Inc.
 
Robusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxRobusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxKnoldus Inc.
 
Optimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxOptimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxKnoldus Inc.
 
Azure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxAzure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxKnoldus Inc.
 
CQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxCQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxKnoldus Inc.
 
ETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationKnoldus Inc.
 
Scripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationScripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationKnoldus Inc.
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIsKnoldus Inc.
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II PresentationKnoldus Inc.
 

Plus de Knoldus Inc. (20)

Authentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxAuthentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptx
 
OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)
 
Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptx
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On Introduction
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptx
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptx
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable Testing
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose Kubernetes
 
Introduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxIntroduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptx
 
Robusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxRobusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptx
 
Optimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxOptimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptx
 
Azure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxAzure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptx
 
CQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxCQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptx
 
ETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake Presentation
 
Scripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationScripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics Presentation
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIs
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II Presentation
 

Dernier

%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 

Dernier (20)

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 

Functors, Applicatives and Monads In Scala

  • 1. Functors,Applicatives and MonadsFunctors,Applicatives and Monads Pallavi Singh Software Consultant Knoldus Software LLP
  • 2. Objectives:  Functors  Applicatives  Monads  Demo Objectives:  Functors  Applicatives  Monads  Demo
  • 3. Problem : We have a simple value We apply a function to it Lets extend it , the value can be in a context, Now when we apply a function to this value,we get results depending on the context. Problem : We have a simple value We apply a function to it Lets extend it , the value can be in a context, Now when we apply a function to this value,we get results depending on the context. Image Source : http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
  • 4. Functors When a value is wrapped in a context, you can’t apply a normal function to the value. We need a map. The map knows how to apply functions to values that are wrapped in a context. Functors When a value is wrapped in a context, you can’t apply a normal function to the value. We need a map. The map knows how to apply functions to values that are wrapped in a context. Image Source : http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
  • 5. Functors Definition : Functor is a type class. A Functor is any data type that defines how map applies to it. Speaking in-formally you apply a function to a wrapped value using map. The map knows how to apply the function. Functors Definition : Functor is a type class. A Functor is any data type that defines how map applies to it. Speaking in-formally you apply a function to a wrapped value using map. The map knows how to apply the function.
  • 6. Functors We have a Constructor C[_] and two types A and B,we want to apply functions of type C[A]=>C[B], so we need adequate transformations ( A=>B ) => ( C[A]=>C[B] ) And we need to define a map def map[A,B](A=>B):(F[A]=>F[B] ) Functors We have a Constructor C[_] and two types A and B,we want to apply functions of type C[A]=>C[B], so we need adequate transformations ( A=>B ) => ( C[A]=>C[B] ) And we need to define a map def map[A,B](A=>B):(F[A]=>F[B] )
  • 7. Functors Example: Options , Streams Object OptionFunctor extends Functor[Option] { def map[A, B](f: A B): Option[A] Option[B] = option option map f⇒ ⇒ ⇒ } Functors Example: Options , Streams Object OptionFunctor extends Functor[Option] { def map[A, B](f: A B): Option[A] Option[B] = option option map f⇒ ⇒ ⇒ }
  • 8. Problem : Given a function what happens when you apply a function to another function , we have another function. Functions are functors too ! A map on a function is function composition. Problem : Given a function what happens when you apply a function to another function , we have another function. Functions are functors too ! A map on a function is function composition. Image Source : http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
  • 9. Problem : We have a value wrapped in context And functions are wrapped in a context too! Problem : We have a value wrapped in context And functions are wrapped in a context too! Image Source : http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
  • 10. Applicatives When a value and function both are wrapped in a context. We can’t apply it as we apply a simple function. We need an apply. It knows how to apply a function wrapped in a context to a value wrapped in a context. 56rt67 Applicatives When a value and function both are wrapped in a context. We can’t apply it as we apply a simple function. We need an apply. It knows how to apply a function wrapped in a context to a value wrapped in a context. 56rt67 Image Source : http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
  • 11. Applicatives Def : Applicative is typeclass. Applicative is any data type that defines how apply applies to it. Apply takes a functor that has a function in it and another functor and extracts that function from the first functor and then maps it over the second one. Speaking in-formally you apply a function wrapped in context to a value wrapped in context. Applicatives Def : Applicative is typeclass. Applicative is any data type that defines how apply applies to it. Apply takes a functor that has a function in it and another functor and extracts that function from the first functor and then maps it over the second one. Speaking in-formally you apply a function wrapped in context to a value wrapped in context. Image Source : http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
  • 12. Applicatives We have a Constructor C[_] and two types A and B, we want to apply functions of type C[A]=>C[B],so we need adequate transformations (C[A=>B] ) => ( C[A]=>C[B] ) And we need to define a apply def apply[A,B](F[A=>B]):(F[A]=>F[B] ) Applicatives We have a Constructor C[_] and two types A and B, we want to apply functions of type C[A]=>C[B],so we need adequate transformations (C[A=>B] ) => ( C[A]=>C[B] ) And we need to define a apply def apply[A,B](F[A=>B]):(F[A]=>F[B] ) Image Source : http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
  • 13. Problem : Given a function what happens if we feed it a wrapped value? Problem : Given a function what happens if we feed it a wrapped value? Image Source : http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
  • 14. Monads Monads apply a function that returns a wrapped value to a wrapped value. Monads Monads apply a function that returns a wrapped value to a wrapped value. Image Source : http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html
  • 16. Monads Definition: Monad is a type class. A monad is a data type that implements the flatMap. Speaking in-formally you apply a function that returns a wrapped value, to a wrapped value. Monads Definition: Monad is a type class. A monad is a data type that implements the flatMap. Speaking in-formally you apply a function that returns a wrapped value, to a wrapped value.
  • 17. Monads We have a Constructor C[_] and two types A and B,we want to apply functions of type C[A]=>C[B], so we need adequate transformations ( A=>C[B] ) => ( C[A]=>C[B] ) And we need to define a flatMap def flatMap[A,B](A=>F[B]):(F[A]=>F[B] ) Monads We have a Constructor C[_] and two types A and B,we want to apply functions of type C[A]=>C[B], so we need adequate transformations ( A=>C[B] ) => ( C[A]=>C[B] ) And we need to define a flatMap def flatMap[A,B](A=>F[B]):(F[A]=>F[B] )
  • 18. Monads Example: List , Set , Option and Future all are Monads Future is a wrapper over some asynchronous operation. Once the future has been completed you can do whatever it is you need to do with its result. Monads Example: List , Set , Option and Future all are Monads Future is a wrapper over some asynchronous operation. Once the future has been completed you can do whatever it is you need to do with its result.
  • 19. Difference b/w Monad and Monoids ? Monoid : Given a type T, a binary operation Op:(T,T)=>T and instance Zero:T then the triple(T, Op , Zero) is called a Monoid if it has the following properties: Neutral Element and Associativity. Monad instance simply wraps the value of type A within the given context and expose a certain set of methods to operate on them, Monoid instance already knows how to combine these values of type A within the given context. Difference b/w Monad and Monoids ? Monoid : Given a type T, a binary operation Op:(T,T)=>T and instance Zero:T then the triple(T, Op , Zero) is called a Monoid if it has the following properties: Neutral Element and Associativity. Monad instance simply wraps the value of type A within the given context and expose a certain set of methods to operate on them, Monoid instance already knows how to combine these values of type A within the given context.
  • 20. Are Monads powerful than Applicatives? Applicatives and monads both model running computations in sequence. But Monads are more powerful because with applicatives you can sequence the computations, but monads allow you to sequence computations with the additional property that the result of subsequent computations can depend on the result of previous computation. Are Monads powerful than Applicatives? Applicatives and monads both model running computations in sequence. But Monads are more powerful because with applicatives you can sequence the computations, but monads allow you to sequence computations with the additional property that the result of subsequent computations can depend on the result of previous computation.
  • 23. References  http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html  http://www.smartjava.org/content/scalaz-features-everyday-usage-part-1-typeclasses- and-scala-extensions  http://eed3si9n.com/learning-scalaz/Applicative.html  https://thedet.wordpress.com/2013/02/11/functors-in-images/  https://thedet.wordpress.com/2012/05/20/functors-monads-applicatives-playing-with- map-functor/ References  http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html  http://www.smartjava.org/content/scalaz-features-everyday-usage-part-1-typeclasses- and-scala-extensions  http://eed3si9n.com/learning-scalaz/Applicative.html  https://thedet.wordpress.com/2013/02/11/functors-in-images/  https://thedet.wordpress.com/2012/05/20/functors-monads-applicatives-playing-with- map-functor/