SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.jsEmanuele DelBono
 
Jetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UIJetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UIGilang Ramadhan
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and FunctionsJussi Pohjolainen
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaSanjeev Tripathi
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
Multithreading and Actors
Multithreading and ActorsMultithreading and Actors
Multithreading and ActorsDiego Pacheco
 
Arriving at monads by going from pure-function composition to effectful-funct...
Arriving at monads by going from pure-function composition to effectful-funct...Arriving at monads by going from pure-function composition to effectful-funct...
Arriving at monads by going from pure-function composition to effectful-funct...Philip Schwarz
 
Sagas Middleware Architecture
Sagas Middleware ArchitectureSagas Middleware Architecture
Sagas Middleware ArchitectureMateusz Bosek
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptWojciech Dzikowski
 
Redux Saga - Under the hood
Redux Saga - Under the hoodRedux Saga - Under the hood
Redux Saga - Under the hoodWaqqas Jabbar
 
Functional Programming In JS
Functional Programming In JSFunctional Programming In JS
Functional Programming In JSDamian Łabas
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Conceptsthinkphp
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6Rob Eisenberg
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and StatementsWebStackAcademy
 

Was ist angesagt? (20)

Solid principles
Solid principlesSolid principles
Solid principles
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
Jetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UIJetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UI
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Async js
Async jsAsync js
Async js
 
Multithreading and Actors
Multithreading and ActorsMultithreading and Actors
Multithreading and Actors
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Arriving at monads by going from pure-function composition to effectful-funct...
Arriving at monads by going from pure-function composition to effectful-funct...Arriving at monads by going from pure-function composition to effectful-funct...
Arriving at monads by going from pure-function composition to effectful-funct...
 
Sagas Middleware Architecture
Sagas Middleware ArchitectureSagas Middleware Architecture
Sagas Middleware Architecture
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
 
Redux Saga - Under the hood
Redux Saga - Under the hoodRedux Saga - Under the hood
Redux Saga - Under the hood
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
Functional Programming In JS
Functional Programming In JSFunctional Programming In JS
Functional Programming In JS
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
JavaScript - Chapter 4 - Types and Statements
 JavaScript - Chapter 4 - Types and Statements JavaScript - Chapter 4 - Types and Statements
JavaScript - Chapter 4 - Types and Statements
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 

Andere mochten auch

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 Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming FundamentalsShahriar Hyder
 
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
 
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
 

Andere mochten auch (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 Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
 
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...
 
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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...kalichargn70th171
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxRTS corp
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxAS Design & AST.
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfkalichargn70th171
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdfSteve Caron
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 

Kürzlich hochgeladen (20)

eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptx
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Mastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptxMastering Project Planning with Microsoft Project 2016.pptx
Mastering Project Planning with Microsoft Project 2016.pptx
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 

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