SlideShare a Scribd company logo
1 of 46
Download to read offline
Functional Programming
Principles & Patterns
Agenda
● Introduction to Functional Programming
● Principles
● Concepts
● Patterns
● Q & A
Code-examples are written in Java and JavaScript
Introduction to Functional Programming
● Benefits
○ Declarative (what vs. how)
○ Scalability / Concurrency
○ Testability
○ Composability & Modularity
○ Ability to reason about programs / Simplicity
○ ...
○ In our case: Broadening our Horizon
● Use-cases
○ Mathematical programming
○ Distributed Systems
○ High Concurrency
○ GUI programming (new!)
○ ...
Functional Programming Languages
● Common Lisp
● Haskell
● SML
● Clojure
● Scala
● Erlang
● (Java)
● (JavaScript)
● ...
Concepts
● Declarative vs. Imperative
● Pure Functions
● Higher Order Functions (+Lambdas)
● Immutability
● Recursion
● Laziness
● map/filter/reduce/zip/flatMap
● Currying
Declarative vs. Imperative
● Defining WHAT to do vs. HOW to do it
● Expressive
● Improve / Optimize underlying algorithms
● Eliminate Side-effects as much as possible
Declarative vs. Imperative - Example
Concepts
● Declarative vs. Imperative
● Pure Functions
● Higher Order Functions (+Lambdas)
● Immutability
● Recursion
● Laziness
● map/filter/reduce/zip/flatMap
● Currying
Pure Functions
● No side-effects
● Referential Transparency (caching, ...)
● Thread-safe
● Compiler-Optimizations
● ...
Concepts
● Declarative vs. Imperative
● Pure Functions
● Higher Order Functions (+Lambdas)
● Immutability
● Recursion
● Laziness
● map/filter/reduce/zip/flatMap
● Currying
Higher Order Functions
● Critical concept in FP
● Functions can take functions as arguments
● Functions can return functions
● Enables functional composition
Higher Order Functions - Example #1
Higher Order Functions - Example #2
Concepts
● Declarative vs. Imperative
● Pure Functions
● Higher Order Functions (+Lambdas)
● Immutability
● Recursion
● Laziness
● map/filter/reduce/zip/flatMap
● Currying
Immutability
● Persistent Data Structures
● Every time a data structure would be mutated, a new one
is returned instead
● Simplifies state management and mutation tracking
● Enables optimizations
● Works well with pure functions
● Memory overhead is mitigated by sharing (Tries)
Concepts
● Declarative vs. Imperative
● Pure Functions
● Higher Order Functions (+Lambdas)
● Immutability
● Recursion
● Laziness
● map/filter/reduce/zip/flatMap
● Currying
Recursion
● Divide and Conquer
● Can provide elegant solutions for complex problems
● Not as complicated to do, if one knows how ;)
Recursion #1
Concepts
● Declarative vs. Imperative
● Pure Functions
● Higher Order Functions (+Lambdas)
● Immutability
● Recursion
● Laziness
● map/filter/reduce/zip/flatMap
● Currying
Laziness
● Evaluation is deferred to the last possible moment
● Avoids needless calculations
● Working with infinite data structures
● Works very well with declarative programming
Laziness Example
Concepts
● Declarative vs. Imperative
● Pure Functions
● Higher Order Functions (+Lambdas)
● Immutability
● Recursion
● Laziness
● map/filter/reduce/zip/flatMap
● Currying
map / Filter / Reduce / Zip
● Backbone of functional programming
map
Filter
Reduce
Zip
Concepts
● Declarative vs. Imperative
● Pure Functions
● Higher Order Functions (+Lambdas)
● Immutability
● Recursion
● Laziness
● map/filter/reduce/zip/flatMap
● Currying
Currying
● Concept by Haskell Curry
● Translating a function that takes multiple arguments into
a sequence of functions which all take 1 argument
● e.g.: add(a, b) AND add(a)(b)
● Improves reusability and composition
● In some languages (Haskell, F#) functions are curried by
default
Currying - Example #1
Currying - Example #2
Currying - Example #3
Patterns
● GOF-Patterns in Functional Style
● Memoization
● Advanced Currying
● Immutability in practice
● Maybe / Optional
● Outlook: Advanced Topics
GOF Patterns vs. Functional Programming
GOF - Decorator (wrapper function)
GOF - Strategy (higher order functions)
Memoization (Caching Technique - Java)
Memoization (Caching Technique - JS)
Immutability in practice
● Data Structures don’t necessarily need to be persistent
in nature
● Use map / filter / reduce
● Examples in JS:
Maybe / Optional
● Pattern for handling absent (e.g.: Null) values
● Avoid annoying if (x==null) checks
● Great for declarative API’s
● Your business logic doesn’t need to deal with null
values, it can just use Maybe()’s
○ At the end, when the actual value is needed, the Maybe can be
evaluated and the null can be handled
Maybe / Optional
Advanced Topics
● Monoids / Functors / Applicatives
● Algebraic Structures in general
● Monads
● Transducers
● ...
Q & A
Resources #1
● https://vimeo.com/113588389
● http://looprecur.com/blog/
● https://www.youtube.com/playlist?list=PLK_hdtAJ4KqX0JOs_KMAmUNTNMRYhWEaC
● http://www.infoq.com/presentations/Simple-Made-Easy
● http://www.infoq.com/presentations/Clojure-Design-Patterns
● https://www.manning.com/books/functional-programming-in-java
● https://dzone.com/articles/functional-programming-java-8
● http://www.vasinov.com/blog/16-months-of-functional-programming/
● https://www.reddit.com/r/functionalprogramming/
● https://github.com/jhusain/learnrxjava/
● http://reactivex.io/learnrx/
● http://blog.jhades.org/java-8-how-to-use-optional/
Resources #2
● http://javascriptair.com/episodes/2015-12-30/
● http://www.amazon.de/Purely-Functional-Data-Structures-Okasaki/dp/0521663504/ref=sr_1_1?ie=UTF8&qid=1452875910&sr=8-1&k
eywords=functional+data+structures
● http://www.amazon.de/Functional-Thinking-Paradigm-Over-Syntax/dp/1449365515/ref=sr_1_1?ie=UTF8&qid=1452875871&sr=8-1&k
eywords=functional+thinking
● http://www.amazon.de/Becoming-Functional-Joshua-Backfield/dp/1449368174/ref=sr_1_1?ie=UTF8&qid=1452875879&sr=8-1&keyw
ords=becoming+functional
● http://www.amazon.de/Functional-JavaScript-Introducing-Programming-Underscore-js/dp/1449360726/ref=sr_1_1?ie=UTF8&qid=145
2875887&sr=8-1&keywords=functional+javascript
● https://github.com/MostlyAdequate/mostly-adequate-guide

More Related Content

What's hot

Javascript under the hood 1
Javascript under the hood 1Javascript under the hood 1
Javascript under the hood 1Thang Tran Duc
 
Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Mindfire Solutions
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous JavascriptGarrett Welson
 
Java 9 New Features
Java 9 New FeaturesJava 9 New Features
Java 9 New FeaturesAli BAKAN
 
JSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPIJSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPIOctavian Nadolu
 
Reactive programming
Reactive programmingReactive programming
Reactive programmingSUDIP GHOSH
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepGuo Albert
 
Domain Modeling in a Functional World
Domain Modeling in a Functional WorldDomain Modeling in a Functional World
Domain Modeling in a Functional WorldDebasish Ghosh
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced JavascriptAdieu
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
 
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
 
Asynchronous programming in C#
Asynchronous programming in C#Asynchronous programming in C#
Asynchronous programming in C#Bohdan Pashkovskyi
 

What's hot (20)

OOP and FP
OOP and FPOOP and FP
OOP and FP
 
Java script ppt
Java script pptJava script ppt
Java script ppt
 
Javascript under the hood 1
Javascript under the hood 1Javascript under the hood 1
Javascript under the hood 1
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 
Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
Java 9 New Features
Java 9 New FeaturesJava 9 New Features
Java 9 New Features
 
JSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPIJSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPI
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Domain Modeling in a Functional World
Domain Modeling in a Functional WorldDomain Modeling in a Functional World
Domain Modeling in a Functional World
 
Advanced Javascript
Advanced JavascriptAdvanced Javascript
Advanced Javascript
 
Async Programming in C# 5
Async Programming in C# 5Async Programming in C# 5
Async Programming in C# 5
 
Ruby
RubyRuby
Ruby
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
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...
 
Introduction to Hibernate
Introduction to HibernateIntroduction to Hibernate
Introduction to Hibernate
 
Asynchronous programming in C#
Asynchronous programming in C#Asynchronous programming in C#
Asynchronous programming in C#
 

Viewers also liked

Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Scott Wlaschin
 
Functional programming for optimization problems in Big Data
Functional programming for optimization problems in Big DataFunctional programming for optimization problems in Big Data
Functional programming for optimization problems in Big DataPaco Nathan
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional ProgrammingAndreas Pauley
 
Introduction To Functional Programming
Introduction To Functional ProgrammingIntroduction To Functional Programming
Introduction To Functional Programmingnewmedio
 
Practical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan HodorogPractical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan Hodorog3Pillar Global
 
那些 Functional Programming 教我的事
那些 Functional Programming 教我的事那些 Functional Programming 教我的事
那些 Functional Programming 教我的事Wen-Tien Chang
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Scott Wlaschin
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scalapramode_ce
 
Functional Reactive Programming in JavaScript
Functional Reactive Programming in JavaScriptFunctional Reactive Programming in JavaScript
Functional Reactive Programming in JavaScriptzupzup.org
 
Running Containerized Node.js Services on AWS Elastic Beanstalk
Running Containerized Node.js Services on AWS Elastic BeanstalkRunning Containerized Node.js Services on AWS Elastic Beanstalk
Running Containerized Node.js Services on AWS Elastic Beanstalkzupzup.org
 
Functional Programing
Functional ProgramingFunctional Programing
Functional ProgramingMax Arshinov
 
WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.
WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.
WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.Oliver Kriska
 
Functional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic ProgrammerFunctional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic ProgrammerRaúl Raja Martínez
 
program development and paradigms
program development and paradigmsprogram development and paradigms
program development and paradigmskasenerd
 
Quality and Software Design Patterns
Quality and Software Design PatternsQuality and Software Design Patterns
Quality and Software Design PatternsPtidej Team
 
Describe professional programing languages and talks
Describe professional programing languages and talks Describe professional programing languages and talks
Describe professional programing languages and talks Ed Bray
 
Building a Large Scale SEO/SEM Application with Apache Solr: Presented by Rah...
Building a Large Scale SEO/SEM Application with Apache Solr: Presented by Rah...Building a Large Scale SEO/SEM Application with Apache Solr: Presented by Rah...
Building a Large Scale SEO/SEM Application with Apache Solr: Presented by Rah...Lucidworks
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programmingAssaf Gannon
 
Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2Raja Hamid
 
Ruby language overview
Ruby language overviewRuby language overview
Ruby language overviewUptech
 

Viewers also liked (20)

Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)
 
Functional programming for optimization problems in Big Data
Functional programming for optimization problems in Big DataFunctional programming for optimization problems in Big Data
Functional programming for optimization problems in Big Data
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
 
Introduction To Functional Programming
Introduction To Functional ProgrammingIntroduction To Functional Programming
Introduction To Functional Programming
 
Practical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan HodorogPractical Functional Programming Presentation by Bogdan Hodorog
Practical Functional Programming Presentation by Bogdan Hodorog
 
那些 Functional Programming 教我的事
那些 Functional Programming 教我的事那些 Functional Programming 教我的事
那些 Functional Programming 教我的事
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
Functional Reactive Programming in JavaScript
Functional Reactive Programming in JavaScriptFunctional Reactive Programming in JavaScript
Functional Reactive Programming in JavaScript
 
Running Containerized Node.js Services on AWS Elastic Beanstalk
Running Containerized Node.js Services on AWS Elastic BeanstalkRunning Containerized Node.js Services on AWS Elastic Beanstalk
Running Containerized Node.js Services on AWS Elastic Beanstalk
 
Functional Programing
Functional ProgramingFunctional Programing
Functional Programing
 
WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.
WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.
WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.
 
Functional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic ProgrammerFunctional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic Programmer
 
program development and paradigms
program development and paradigmsprogram development and paradigms
program development and paradigms
 
Quality and Software Design Patterns
Quality and Software Design PatternsQuality and Software Design Patterns
Quality and Software Design Patterns
 
Describe professional programing languages and talks
Describe professional programing languages and talks Describe professional programing languages and talks
Describe professional programing languages and talks
 
Building a Large Scale SEO/SEM Application with Apache Solr: Presented by Rah...
Building a Large Scale SEO/SEM Application with Apache Solr: Presented by Rah...Building a Large Scale SEO/SEM Application with Apache Solr: Presented by Rah...
Building a Large Scale SEO/SEM Application with Apache Solr: Presented by Rah...
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programming
 
Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2Programming fundamentals lecture 1&2
Programming fundamentals lecture 1&2
 
Ruby language overview
Ruby language overviewRuby language overview
Ruby language overview
 

Similar to Functional Programming Principles & Patterns

Functional Programming in Ruby
Functional Programming in RubyFunctional Programming in Ruby
Functional Programming in RubyAlex Teut
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scaladatamantra
 
Advanced memory allocation
Advanced memory allocationAdvanced memory allocation
Advanced memory allocationJoris Bonnefoy
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programmingKonrad Szydlo
 
Reactive Software Systems
Reactive Software SystemsReactive Software Systems
Reactive Software SystemsBehrad Zari
 
Paper_An Efficient Garbage Collection in Java Virtual Machine via Swap I/O O...
Paper_An Efficient Garbage Collection in Java Virtual  Machine via Swap I/O O...Paper_An Efficient Garbage Collection in Java Virtual  Machine via Swap I/O O...
Paper_An Efficient Garbage Collection in Java Virtual Machine via Swap I/O O...Hyo jeong Lee
 
Improving PySpark performance: Spark Performance Beyond the JVM
Improving PySpark performance: Spark Performance Beyond the JVMImproving PySpark performance: Spark Performance Beyond the JVM
Improving PySpark performance: Spark Performance Beyond the JVMHolden Karau
 
The productivity brought by Clojure
The productivity brought by ClojureThe productivity brought by Clojure
The productivity brought by ClojureLaurence Chen
 
Winning data science competitions, presented by Owen Zhang
Winning data science competitions, presented by Owen ZhangWinning data science competitions, presented by Owen Zhang
Winning data science competitions, presented by Owen ZhangVivian S. Zhang
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytechyannick grenzinger
 
SOLID refactoring - racing car katas
SOLID refactoring - racing car katasSOLID refactoring - racing car katas
SOLID refactoring - racing car katasGeorg Berky
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextUnfold UI
 
Software Design Practices for Large-Scale Automation
Software Design Practices for Large-Scale AutomationSoftware Design Practices for Large-Scale Automation
Software Design Practices for Large-Scale AutomationHao Xu
 
An Intro to Scala for PHP Developers
An Intro to Scala for PHP DevelopersAn Intro to Scala for PHP Developers
An Intro to Scala for PHP DevelopersHuffPost Code
 
Kotlin functional programming basic@Kotlin TW study group
Kotlin  functional programming basic@Kotlin TW study groupKotlin  functional programming basic@Kotlin TW study group
Kotlin functional programming basic@Kotlin TW study groupJulian Yu-Lang Chu
 
A super fast introduction to Spark and glance at BEAM
A super fast introduction to Spark and glance at BEAMA super fast introduction to Spark and glance at BEAM
A super fast introduction to Spark and glance at BEAMHolden Karau
 

Similar to Functional Programming Principles & Patterns (20)

Functional Programming in Ruby
Functional Programming in RubyFunctional Programming in Ruby
Functional Programming in Ruby
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
 
Advanced memory allocation
Advanced memory allocationAdvanced memory allocation
Advanced memory allocation
 
Memory in go
Memory in goMemory in go
Memory in go
 
Progress_190213
Progress_190213Progress_190213
Progress_190213
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programming
 
Reactive Software Systems
Reactive Software SystemsReactive Software Systems
Reactive Software Systems
 
Paper_An Efficient Garbage Collection in Java Virtual Machine via Swap I/O O...
Paper_An Efficient Garbage Collection in Java Virtual  Machine via Swap I/O O...Paper_An Efficient Garbage Collection in Java Virtual  Machine via Swap I/O O...
Paper_An Efficient Garbage Collection in Java Virtual Machine via Swap I/O O...
 
Improving PySpark performance: Spark Performance Beyond the JVM
Improving PySpark performance: Spark Performance Beyond the JVMImproving PySpark performance: Spark Performance Beyond the JVM
Improving PySpark performance: Spark Performance Beyond the JVM
 
Introduction to Functional programming
Introduction to Functional programmingIntroduction to Functional programming
Introduction to Functional programming
 
The productivity brought by Clojure
The productivity brought by ClojureThe productivity brought by Clojure
The productivity brought by Clojure
 
Winning data science competitions, presented by Owen Zhang
Winning data science competitions, presented by Owen ZhangWinning data science competitions, presented by Owen Zhang
Winning data science competitions, presented by Owen Zhang
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
SOLID refactoring - racing car katas
SOLID refactoring - racing car katasSOLID refactoring - racing car katas
SOLID refactoring - racing car katas
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNext
 
Software Design Practices for Large-Scale Automation
Software Design Practices for Large-Scale AutomationSoftware Design Practices for Large-Scale Automation
Software Design Practices for Large-Scale Automation
 
Progress_190130
Progress_190130Progress_190130
Progress_190130
 
An Intro to Scala for PHP Developers
An Intro to Scala for PHP DevelopersAn Intro to Scala for PHP Developers
An Intro to Scala for PHP Developers
 
Kotlin functional programming basic@Kotlin TW study group
Kotlin  functional programming basic@Kotlin TW study groupKotlin  functional programming basic@Kotlin TW study group
Kotlin functional programming basic@Kotlin TW study group
 
A super fast introduction to Spark and glance at BEAM
A super fast introduction to Spark and glance at BEAMA super fast introduction to Spark and glance at BEAM
A super fast introduction to Spark and glance at BEAM
 

Recently uploaded

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

Recently uploaded (20)

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

Functional Programming Principles & Patterns

  • 2. Agenda ● Introduction to Functional Programming ● Principles ● Concepts ● Patterns ● Q & A Code-examples are written in Java and JavaScript
  • 3. Introduction to Functional Programming ● Benefits ○ Declarative (what vs. how) ○ Scalability / Concurrency ○ Testability ○ Composability & Modularity ○ Ability to reason about programs / Simplicity ○ ... ○ In our case: Broadening our Horizon ● Use-cases ○ Mathematical programming ○ Distributed Systems ○ High Concurrency ○ GUI programming (new!) ○ ...
  • 4. Functional Programming Languages ● Common Lisp ● Haskell ● SML ● Clojure ● Scala ● Erlang ● (Java) ● (JavaScript) ● ...
  • 5. Concepts ● Declarative vs. Imperative ● Pure Functions ● Higher Order Functions (+Lambdas) ● Immutability ● Recursion ● Laziness ● map/filter/reduce/zip/flatMap ● Currying
  • 6. Declarative vs. Imperative ● Defining WHAT to do vs. HOW to do it ● Expressive ● Improve / Optimize underlying algorithms ● Eliminate Side-effects as much as possible
  • 8. Concepts ● Declarative vs. Imperative ● Pure Functions ● Higher Order Functions (+Lambdas) ● Immutability ● Recursion ● Laziness ● map/filter/reduce/zip/flatMap ● Currying
  • 9. Pure Functions ● No side-effects ● Referential Transparency (caching, ...) ● Thread-safe ● Compiler-Optimizations ● ...
  • 10. Concepts ● Declarative vs. Imperative ● Pure Functions ● Higher Order Functions (+Lambdas) ● Immutability ● Recursion ● Laziness ● map/filter/reduce/zip/flatMap ● Currying
  • 11. Higher Order Functions ● Critical concept in FP ● Functions can take functions as arguments ● Functions can return functions ● Enables functional composition
  • 12. Higher Order Functions - Example #1
  • 13. Higher Order Functions - Example #2
  • 14. Concepts ● Declarative vs. Imperative ● Pure Functions ● Higher Order Functions (+Lambdas) ● Immutability ● Recursion ● Laziness ● map/filter/reduce/zip/flatMap ● Currying
  • 15. Immutability ● Persistent Data Structures ● Every time a data structure would be mutated, a new one is returned instead ● Simplifies state management and mutation tracking ● Enables optimizations ● Works well with pure functions ● Memory overhead is mitigated by sharing (Tries)
  • 16. Concepts ● Declarative vs. Imperative ● Pure Functions ● Higher Order Functions (+Lambdas) ● Immutability ● Recursion ● Laziness ● map/filter/reduce/zip/flatMap ● Currying
  • 17. Recursion ● Divide and Conquer ● Can provide elegant solutions for complex problems ● Not as complicated to do, if one knows how ;)
  • 19. Concepts ● Declarative vs. Imperative ● Pure Functions ● Higher Order Functions (+Lambdas) ● Immutability ● Recursion ● Laziness ● map/filter/reduce/zip/flatMap ● Currying
  • 20. Laziness ● Evaluation is deferred to the last possible moment ● Avoids needless calculations ● Working with infinite data structures ● Works very well with declarative programming
  • 22. Concepts ● Declarative vs. Imperative ● Pure Functions ● Higher Order Functions (+Lambdas) ● Immutability ● Recursion ● Laziness ● map/filter/reduce/zip/flatMap ● Currying
  • 23. map / Filter / Reduce / Zip ● Backbone of functional programming
  • 24. map
  • 27. Zip
  • 28. Concepts ● Declarative vs. Imperative ● Pure Functions ● Higher Order Functions (+Lambdas) ● Immutability ● Recursion ● Laziness ● map/filter/reduce/zip/flatMap ● Currying
  • 29. Currying ● Concept by Haskell Curry ● Translating a function that takes multiple arguments into a sequence of functions which all take 1 argument ● e.g.: add(a, b) AND add(a)(b) ● Improves reusability and composition ● In some languages (Haskell, F#) functions are curried by default
  • 33. Patterns ● GOF-Patterns in Functional Style ● Memoization ● Advanced Currying ● Immutability in practice ● Maybe / Optional ● Outlook: Advanced Topics
  • 34. GOF Patterns vs. Functional Programming
  • 35. GOF - Decorator (wrapper function)
  • 36. GOF - Strategy (higher order functions)
  • 39. Immutability in practice ● Data Structures don’t necessarily need to be persistent in nature ● Use map / filter / reduce ● Examples in JS:
  • 40. Maybe / Optional ● Pattern for handling absent (e.g.: Null) values ● Avoid annoying if (x==null) checks ● Great for declarative API’s ● Your business logic doesn’t need to deal with null values, it can just use Maybe()’s ○ At the end, when the actual value is needed, the Maybe can be evaluated and the null can be handled
  • 42. Advanced Topics ● Monoids / Functors / Applicatives ● Algebraic Structures in general ● Monads ● Transducers ● ...
  • 43. Q & A
  • 44.
  • 45. Resources #1 ● https://vimeo.com/113588389 ● http://looprecur.com/blog/ ● https://www.youtube.com/playlist?list=PLK_hdtAJ4KqX0JOs_KMAmUNTNMRYhWEaC ● http://www.infoq.com/presentations/Simple-Made-Easy ● http://www.infoq.com/presentations/Clojure-Design-Patterns ● https://www.manning.com/books/functional-programming-in-java ● https://dzone.com/articles/functional-programming-java-8 ● http://www.vasinov.com/blog/16-months-of-functional-programming/ ● https://www.reddit.com/r/functionalprogramming/ ● https://github.com/jhusain/learnrxjava/ ● http://reactivex.io/learnrx/ ● http://blog.jhades.org/java-8-how-to-use-optional/
  • 46. Resources #2 ● http://javascriptair.com/episodes/2015-12-30/ ● http://www.amazon.de/Purely-Functional-Data-Structures-Okasaki/dp/0521663504/ref=sr_1_1?ie=UTF8&qid=1452875910&sr=8-1&k eywords=functional+data+structures ● http://www.amazon.de/Functional-Thinking-Paradigm-Over-Syntax/dp/1449365515/ref=sr_1_1?ie=UTF8&qid=1452875871&sr=8-1&k eywords=functional+thinking ● http://www.amazon.de/Becoming-Functional-Joshua-Backfield/dp/1449368174/ref=sr_1_1?ie=UTF8&qid=1452875879&sr=8-1&keyw ords=becoming+functional ● http://www.amazon.de/Functional-JavaScript-Introducing-Programming-Underscore-js/dp/1449360726/ref=sr_1_1?ie=UTF8&qid=145 2875887&sr=8-1&keywords=functional+javascript ● https://github.com/MostlyAdequate/mostly-adequate-guide