SlideShare a Scribd company logo
1 of 20
Download to read offline
3 FP Concepts




                Recursion, List comprehensions and Monads



@diego_pacheco  about.me/diegopacheco
3 FP Concepts
  Recursion

  List Comprehensions

  Monads
Recursion
Recursion

 Function defined inside a function
 Function calling it-self
 Defining an infinite set of objects by a finite
statement (Recursion Power by Wikipedia)
 Same behavior as loop, for, while, etc…
Recursion
List Comprehensions
List Comprehensions

 Syntactic construct based on lists
 Inspired by math: set comprehensions
 Expressions on lists, powerful stuff!
List Comprehensions
Monads
Monads => NO State on a world FULL of
State, Looks nonsense!? WTF?
FP/Haskell are against state? Hell No!
It’s all about discipline state…
How to Deal with state without global
shared state variables ?
Workaround => Truck Food as Monad !!!
  (Abstraction)
Monads

 Deal with side-effects in a functional way
 Mathematical construct
 Without monads PURE FP would be nuts
 Functional able todo IO
 Good to Control tracking of things
 Similar to AOP Interceptors
 Function Composition: LINQ, Unix Pipes
 You can build environments that support exactly
the features that you want (Scala Option[A])
 Encapsulating two things:
   control flow (Maybe, Error, List, Continuation, parser monads)
   state propagation (State, Reader, Writer, IO)
Monads as types/class (>>=), OOP!?
Monads have laws…
                        its not just type/classes
                        Make possible assumptions about the
                        type/class and his behavior.


1. Left Identity (apply function to value)
     return x >>= f (the same as) f x
     sample: return 3 >>= (x -> Just (x+100000))
2. Right Identity (value to feed return)
     m >>= return (the same as) m
     sample: [1,2,3,4] >>= (x -> return x)
3. Associativity (no matter how nested chain)
     (m >>= f) >>= g (the same as) m >>= (x -> f x >>= g)
     sample: return (0,0) >>= landRight 2 >>= landLeft 2 >>= landRight 2
Monads

         >>= (bind)
Monads
https://github.com/diegopacheco/functional-society
3 FP Concepts

                   Thank You!
                    Obrigado!
                Higher Order Functions, Lambda and Currying



@diego_pacheco  about.me/diegopacheco

More Related Content

Viewers also liked (17)

Tech Evaluation
Tech EvaluationTech Evaluation
Tech Evaluation
 
3 little clojure functions 4
3 little clojure functions 43 little clojure functions 4
3 little clojure functions 4
 
Spring Capitulo 02
Spring Capitulo 02Spring Capitulo 02
Spring Capitulo 02
 
Packer
PackerPacker
Packer
 
Vacations @ 2012 -1
Vacations @ 2012 -1Vacations @ 2012 -1
Vacations @ 2012 -1
 
Ring
RingRing
Ring
 
Terraform
TerraformTerraform
Terraform
 
Delivering happiness
Delivering happinessDelivering happiness
Delivering happiness
 
Snowplow Analitics
Snowplow AnaliticsSnowplow Analitics
Snowplow Analitics
 
Scala FS 2012
Scala FS 2012Scala FS 2012
Scala FS 2012
 
Apache Storm
Apache StormApache Storm
Apache Storm
 
Throughtput dos Coachs
Throughtput dos CoachsThroughtput dos Coachs
Throughtput dos Coachs
 
Netty
NettyNetty
Netty
 
is TDD Dead? System Nature is the anwser!
is TDD Dead? System Nature is the anwser!is TDD Dead? System Nature is the anwser!
is TDD Dead? System Nature is the anwser!
 
Soa Governance Made Easy
Soa Governance Made EasySoa Governance Made Easy
Soa Governance Made Easy
 
Irrational cognitive biases
Irrational cognitive biasesIrrational cognitive biases
Irrational cognitive biases
 
Lean Architecture
Lean ArchitectureLean Architecture
Lean Architecture
 

Similar to 3 FP Concepts: Recursion, List Comprehensions and Monads

Ti1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismTi1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: Polymorphism
Eelco Visser
 

Similar to 3 FP Concepts: Recursion, List Comprehensions and Monads (20)

scala.reflect, Eugene Burmako
scala.reflect, Eugene Burmakoscala.reflect, Eugene Burmako
scala.reflect, Eugene Burmako
 
Евгений Бурмако «scala.reflect»
Евгений Бурмако «scala.reflect»Евгений Бурмако «scala.reflect»
Евгений Бурмако «scala.reflect»
 
Fuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional ProgrammingFuel Up JavaScript with Functional Programming
Fuel Up JavaScript with Functional Programming
 
Practical cats
Practical catsPractical cats
Practical cats
 
Scala Introduction
Scala IntroductionScala Introduction
Scala Introduction
 
Introduction to Functional Languages
Introduction to Functional LanguagesIntroduction to Functional Languages
Introduction to Functional Languages
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskell
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Principles of functional progrmming in scala
Principles of functional progrmming in scalaPrinciples of functional progrmming in scala
Principles of functional progrmming in scala
 
Frp2016 3
Frp2016 3Frp2016 3
Frp2016 3
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako,
 
Ti1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismTi1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: Polymorphism
 
Scala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsScala. Introduction to FP. Monads
Scala. Introduction to FP. Monads
 
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...
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Lambdas: Myths and Mistakes
Lambdas: Myths and MistakesLambdas: Myths and Mistakes
Lambdas: Myths and Mistakes
 
Knowledge Extraction
Knowledge ExtractionKnowledge Extraction
Knowledge Extraction
 
C# programming
C# programming C# programming
C# programming
 
Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With Scala
 
Google06
Google06Google06
Google06
 

More from Diego Pacheco

More from Diego Pacheco (20)

Naming Things Book : Simple Book Review!
Naming Things Book : Simple Book Review!Naming Things Book : Simple Book Review!
Naming Things Book : Simple Book Review!
 
Continuous Discovery Habits Book Review.pdf
Continuous Discovery Habits  Book Review.pdfContinuous Discovery Habits  Book Review.pdf
Continuous Discovery Habits Book Review.pdf
 
Thoughts about Shape Up
Thoughts about Shape UpThoughts about Shape Up
Thoughts about Shape Up
 
Holacracy
HolacracyHolacracy
Holacracy
 
AWS IAM
AWS IAMAWS IAM
AWS IAM
 
CDKs
CDKsCDKs
CDKs
 
Encryption Deep Dive
Encryption Deep DiveEncryption Deep Dive
Encryption Deep Dive
 
Sec 101
Sec 101Sec 101
Sec 101
 
Reflections on SCM
Reflections on SCMReflections on SCM
Reflections on SCM
 
Management: Doing the non-obvious! III
Management: Doing the non-obvious! IIIManagement: Doing the non-obvious! III
Management: Doing the non-obvious! III
 
Design is not Subjective
Design is not SubjectiveDesign is not Subjective
Design is not Subjective
 
Architecture & Engineering : Doing the non-obvious!
Architecture & Engineering :  Doing the non-obvious!Architecture & Engineering :  Doing the non-obvious!
Architecture & Engineering : Doing the non-obvious!
 
Management doing the non-obvious II
Management doing the non-obvious II Management doing the non-obvious II
Management doing the non-obvious II
 
Testing in production
Testing in productionTesting in production
Testing in production
 
Nine lies about work
Nine lies about workNine lies about work
Nine lies about work
 
Management: doing the nonobvious!
Management: doing the nonobvious!Management: doing the nonobvious!
Management: doing the nonobvious!
 
AI and the Future
AI and the FutureAI and the Future
AI and the Future
 
Dealing with dependencies
Dealing  with dependenciesDealing  with dependencies
Dealing with dependencies
 
Dealing with dependencies in tests
Dealing  with dependencies in testsDealing  with dependencies in tests
Dealing with dependencies in tests
 
Kanban 2020
Kanban 2020Kanban 2020
Kanban 2020
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

3 FP Concepts: Recursion, List Comprehensions and Monads

  • 1. 3 FP Concepts Recursion, List comprehensions and Monads @diego_pacheco  about.me/diegopacheco
  • 2. 3 FP Concepts Recursion List Comprehensions Monads
  • 4. Recursion  Function defined inside a function  Function calling it-self  Defining an infinite set of objects by a finite statement (Recursion Power by Wikipedia)  Same behavior as loop, for, while, etc…
  • 7. List Comprehensions  Syntactic construct based on lists  Inspired by math: set comprehensions  Expressions on lists, powerful stuff!
  • 10. Monads => NO State on a world FULL of State, Looks nonsense!? WTF?
  • 11. FP/Haskell are against state? Hell No! It’s all about discipline state…
  • 12. How to Deal with state without global shared state variables ?
  • 13. Workaround => Truck Food as Monad !!! (Abstraction)
  • 14. Monads  Deal with side-effects in a functional way  Mathematical construct  Without monads PURE FP would be nuts  Functional able todo IO  Good to Control tracking of things  Similar to AOP Interceptors  Function Composition: LINQ, Unix Pipes  You can build environments that support exactly the features that you want (Scala Option[A])  Encapsulating two things:  control flow (Maybe, Error, List, Continuation, parser monads)  state propagation (State, Reader, Writer, IO)
  • 15. Monads as types/class (>>=), OOP!?
  • 16. Monads have laws… its not just type/classes Make possible assumptions about the type/class and his behavior. 1. Left Identity (apply function to value) return x >>= f (the same as) f x sample: return 3 >>= (x -> Just (x+100000)) 2. Right Identity (value to feed return) m >>= return (the same as) m sample: [1,2,3,4] >>= (x -> return x) 3. Associativity (no matter how nested chain) (m >>= f) >>= g (the same as) m >>= (x -> f x >>= g) sample: return (0,0) >>= landRight 2 >>= landLeft 2 >>= landRight 2
  • 17. Monads >>= (bind)
  • 20. 3 FP Concepts Thank You! Obrigado! Higher Order Functions, Lambda and Currying @diego_pacheco  about.me/diegopacheco