SlideShare a Scribd company logo
Some basic FP concepts 
@friemens
Why is mutable state problematic? 
Functions as Values 
Programming without assignment? 
Handle mutable state safely 
Leave data alone!
Nothing new here! 
1930s Lambda Calculus 
1960s Lisp 
1990s Haskell
„Familiarity and Simplicity are orthogonal concepts.“ 
Rich Hickey
Why is mutable state problematic?
A system without side-effects is useless, 
but...
Mutation hinders reasoning.
Mutable state increases test effort.
1. 2. 
Mutation introduces order.
Mutable state makes concurrency hard.
FP programming 
OOP programming 
Side-effects restrict how the machine can help us.
Some basic FP concepts
Context dependance 
Pure Functions 
Side-effects 
The future-proof structure of any software system.
Functions as Values
Pure Function 
= 
No side-effects 
+ 
Result depends only on param values
Lambda Expression 
= 
An anonymous function.
Closure 
= 
A function + some captured environment.
Higher-Order Function 
Fn: [Any... -> Any] 
F: [Any -> Fn] 
G: [Fn -> Any] 
H: [Fn -> Fn] 
A function that 
- does something with another function 
- or returns a function, 
- or both.
Function Application 
Fn: [Any... -> Any] 
apply: [Fn Any* -> Any] 
Take collection of param values 
and invoke function.
Partial Application 
Fn: [Any1...Anym...Anyn -> Any] 
partial: [Fn Any1...Anym -> 
[Anym+1...Anyn -> Any]] 
Create a new function with some arguments 
fixed. 
(„Currying“ is automatic partial application.)
Function Composition 
F: [X -> Y] 
G: [Y -> Z] 
compose: [G F -> [X -> Z]] 
Concatenate computations.
Programming without assignment?
Good bye =, for, while and cousins, ... 
… say hello to let, map, filter and friends!
map 
Thinking in collection transformations. 
xs 
ys 
z 
filter 
concat reduce
map filter mapcat into 
Don't be so eager!
Cheap parallelization. 
reduce 
combine
Handle mutable state safely
State x State x' 
f 
swap! 
Identity 
Separate state from identity.
Give identities well-defined concurrency semantics.
Share immutable state liberally. 
Be restrictive with access to identities.
Leave data alone!
BigHero 
-a string 
-a map 
+method1 
+method2 
+method3 
Objects claim feature completeness.
You can't foresee the future.
You will violate the Open-Closed-Principle.
„Inventing a class with its own interface 
to hold a piece of information is like inventing 
a new language to write every short story. “ 
Rich Hickey
Data is simple.
DSL 
API 
Data Model
Wrap up
OO makes code understandable 
by encapsulating moving parts. 
FP makes code understandable 
by minimizing moving parts. 
Michael Feathers
The future is functional. 
You need to practice FP before you „get“ it. 
It's more fun!
Questions?

More Related Content

PPTX
Dev Concepts: Functional Programming
Svetlin Nakov
 
PDF
Functional programing in Javascript (lite intro)
Nikos Kalogridis
 
PPTX
Functional programming
Kibru Demeke
 
PPTX
An Introduction to Functional Programming with Javascript
Doug Sparling
 
PPTX
Anonymous and Inline Functions in MATLAB
Shameer Ahmed Koya
 
PPTX
Function overloading and overriding
Rajab Ali
 
PDF
Thinking in Functions: Functional Programming in Python
Anoop Thomas Mathew
 
PDF
Introduction to functional programming
Konrad Szydlo
 
Dev Concepts: Functional Programming
Svetlin Nakov
 
Functional programing in Javascript (lite intro)
Nikos Kalogridis
 
Functional programming
Kibru Demeke
 
An Introduction to Functional Programming with Javascript
Doug Sparling
 
Anonymous and Inline Functions in MATLAB
Shameer Ahmed Koya
 
Function overloading and overriding
Rajab Ali
 
Thinking in Functions: Functional Programming in Python
Anoop Thomas Mathew
 
Introduction to functional programming
Konrad Szydlo
 

What's hot (19)

PPTX
User Defined Functions in MATLAB Part-4
Shameer Ahmed Koya
 
PPTX
User defined Functions in MATLAB Part 1
Shameer Ahmed Koya
 
PDF
Functional Python Webinar from October 22nd, 2014
Reuven Lerner
 
PPT
3 Function Overloading
Praveen M Jigajinni
 
PDF
Introduction to functional programming (In Arabic)
Omar Abdelhafith
 
PPTX
Function overloading in c++
Learn By Watch
 
PPTX
Functions in c
kalavathisugan
 
PPTX
Function
jasscheema
 
PPTX
Functional Programming with JavaScript
Aung Baw
 
PPTX
PHP = PHunctional Programming
Luis Atencio
 
PPTX
Virtual function in C++ Pure Virtual Function
Kamlesh Makvana
 
PPT
Function overloading(C++)
Ritika Sharma
 
PPTX
Functional programming in JavaScript
Joseph Smith
 
PPTX
Storage Classes and Functions
Jake Bond
 
PDF
Introduction to C++
Pranali Chaudhari
 
PPTX
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
PDF
Functional go
Geison Goes
 
PDF
Ruby Functional Programming
Geison Goes
 
PDF
CSEG1001 Unit 5 Structure and Unions
Dhiviya Rose
 
User Defined Functions in MATLAB Part-4
Shameer Ahmed Koya
 
User defined Functions in MATLAB Part 1
Shameer Ahmed Koya
 
Functional Python Webinar from October 22nd, 2014
Reuven Lerner
 
3 Function Overloading
Praveen M Jigajinni
 
Introduction to functional programming (In Arabic)
Omar Abdelhafith
 
Function overloading in c++
Learn By Watch
 
Functions in c
kalavathisugan
 
Function
jasscheema
 
Functional Programming with JavaScript
Aung Baw
 
PHP = PHunctional Programming
Luis Atencio
 
Virtual function in C++ Pure Virtual Function
Kamlesh Makvana
 
Function overloading(C++)
Ritika Sharma
 
Functional programming in JavaScript
Joseph Smith
 
Storage Classes and Functions
Jake Bond
 
Introduction to C++
Pranali Chaudhari
 
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
Functional go
Geison Goes
 
Ruby Functional Programming
Geison Goes
 
CSEG1001 Unit 5 Structure and Unions
Dhiviya Rose
 
Ad

Viewers also liked (14)

PDF
Clojure+ClojureScript Webapps
Falko Riemenschneider
 
PDF
ClojureScript Introduction
Falko Riemenschneider
 
PDF
Clojure - Why does it matter?
Falko Riemenschneider
 
PDF
Making design decisions in React-based ClojureScript web applications
Falko Riemenschneider
 
PDF
ClojureScript - A functional Lisp for the browser
Falko Riemenschneider
 
PDF
An Adventure in Serverless ClojureScript
Norman Richards
 
PDF
Why you should be excited about ClojureScript
elliando dias
 
PDF
JavaFX GUI architecture with Clojure core.async
Falko Riemenschneider
 
PPTX
FlatGUI: Reactive GUI Toolkit Implemented in Clojure
denyslebediev
 
PDF
All for Web development
Thuyet Nguyen
 
PDF
Clojurescript slides
elliando dias
 
PDF
Thinking Functionally with Clojure
John Stevenson
 
PPTX
CLI utility in ClojureScript running on Node.js
Karolis Labrencis
 
PDF
Build Features, Not Apps
Natasha Murashev
 
Clojure+ClojureScript Webapps
Falko Riemenschneider
 
ClojureScript Introduction
Falko Riemenschneider
 
Clojure - Why does it matter?
Falko Riemenschneider
 
Making design decisions in React-based ClojureScript web applications
Falko Riemenschneider
 
ClojureScript - A functional Lisp for the browser
Falko Riemenschneider
 
An Adventure in Serverless ClojureScript
Norman Richards
 
Why you should be excited about ClojureScript
elliando dias
 
JavaFX GUI architecture with Clojure core.async
Falko Riemenschneider
 
FlatGUI: Reactive GUI Toolkit Implemented in Clojure
denyslebediev
 
All for Web development
Thuyet Nguyen
 
Clojurescript slides
elliando dias
 
Thinking Functionally with Clojure
John Stevenson
 
CLI utility in ClojureScript running on Node.js
Karolis Labrencis
 
Build Features, Not Apps
Natasha Murashev
 
Ad

Similar to Some basic FP concepts (20)

PDF
Functional Go
Geison Goes
 
PPTX
05 functional programming
Victor Matyushevskyy
 
PDF
Functional Swift
Geison Goes
 
PDF
The Fuss about || Haskell | Scala | F# ||
Ashwin Rao
 
PPTX
ScalaDays 2013 Keynote Speech by Martin Odersky
Typesafe
 
PDF
Go Beyond Higher Order Functions: A Journey into Functional Programming
Lex Sheehan
 
PDF
Functional programming and Elm
Fangda Wang
 
ODP
Functional programming
S M Asaduzzaman
 
ODP
Clojure
alandipert
 
PPTX
Turing Goes to Church
Steve Poling
 
PPTX
When life gives you functions make functional programs!
Aaron Levin
 
PDF
From DOT to Dotty
Martin Odersky
 
PDF
Intro to Functional Programming @ Scala Montreal
felixtrepanier
 
PDF
DEF CON 27 - workshop - EIGENTOURIST - hacking with monads
Felipe Prado
 
PPTX
Intro f# functional_programming
Mauro Ghiani
 
PDF
If You Think You Can Stay Away from Functional Programming, You Are Wrong
Mario Fusco
 
PDF
Functional Programming
Yuan Wang
 
PPT
Scala Talk at FOSDEM 2009
Martin Odersky
 
PDF
Python idiomatico
PyCon Italia
 
PDF
Pydiomatic
rik0
 
Functional Go
Geison Goes
 
05 functional programming
Victor Matyushevskyy
 
Functional Swift
Geison Goes
 
The Fuss about || Haskell | Scala | F# ||
Ashwin Rao
 
ScalaDays 2013 Keynote Speech by Martin Odersky
Typesafe
 
Go Beyond Higher Order Functions: A Journey into Functional Programming
Lex Sheehan
 
Functional programming and Elm
Fangda Wang
 
Functional programming
S M Asaduzzaman
 
Clojure
alandipert
 
Turing Goes to Church
Steve Poling
 
When life gives you functions make functional programs!
Aaron Levin
 
From DOT to Dotty
Martin Odersky
 
Intro to Functional Programming @ Scala Montreal
felixtrepanier
 
DEF CON 27 - workshop - EIGENTOURIST - hacking with monads
Felipe Prado
 
Intro f# functional_programming
Mauro Ghiani
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
Mario Fusco
 
Functional Programming
Yuan Wang
 
Scala Talk at FOSDEM 2009
Martin Odersky
 
Python idiomatico
PyCon Italia
 
Pydiomatic
rik0
 

Recently uploaded (20)

PPTX
Design Tips to Help Non-Visual Visitors Stay Safe Online
Daniela Napoli
 
PPTX
Rotary_Fundraising_Overview_Updated_new video .pptx
allangraemeduncan
 
PDF
Securing Africa’s future: Technology, culture and the changing face of threat
Kayode Fayemi
 
PDF
Mathematics Grade 11 Term 1 Week 1_2021.pdf
MalepyaneMokgatle
 
PDF
Green Natural Green House Presentation (2).pdf
SaeedOsman6
 
DOCX
Ss Peter & Paul Choir Formation Training
kiambutownshipsecond
 
PPTX
Remote Healthcare Technology Use Cases and the Contextual Integrity of Olde...
Daniela Napoli
 
PPTX
A Power Point Presentaion of 2 test match
katarapiyush21
 
PPTX
Joy And Peace In All Circumstances.pptx
FamilyWorshipCenterD
 
PPTX
Introductions to artificial intelligence
rakshjain77
 
PPTX
Public Speakingbjdsbkjfdkjdasnlkdasnlknadslnbsjknsakjscbnkjbncs.pptx
ranazunairriaz1
 
PDF
50 Breathtaking WWII Colorized Photos Look Like They Were Taken Yesterday
Ivan Consiglio
 
PPTX
Mastering the DevOps Certification: CI/CD, Governance & Monitoring Made Simple
shubhamsharma994585
 
PPTX
Marketing Mix Analysis of Singapore Airlines.pptx
auntorkhastagirpujan
 
PPTX
Selecting relevant value chain/s for Impactful Development Policies
Francois Stepman
 
PPTX
GAMABA AWARDEES GINAW BILOG AND SALINTA MONON BY REYMART
purezagambala458
 
PPTX
Iconic Destinations in India: Explore Heritage and Beauty
dhorashankar
 
PDF
Chapter-52-Relationship-between-countries-at-different-levels-of-development-...
dinhminhthu1405
 
PPTX
DPIC Assingment_1.pptx.pptx for presentation
yashwork2607
 
PPTX
2025-07-27 Abraham 09 (shared slides).pptx
Dale Wells
 
Design Tips to Help Non-Visual Visitors Stay Safe Online
Daniela Napoli
 
Rotary_Fundraising_Overview_Updated_new video .pptx
allangraemeduncan
 
Securing Africa’s future: Technology, culture and the changing face of threat
Kayode Fayemi
 
Mathematics Grade 11 Term 1 Week 1_2021.pdf
MalepyaneMokgatle
 
Green Natural Green House Presentation (2).pdf
SaeedOsman6
 
Ss Peter & Paul Choir Formation Training
kiambutownshipsecond
 
Remote Healthcare Technology Use Cases and the Contextual Integrity of Olde...
Daniela Napoli
 
A Power Point Presentaion of 2 test match
katarapiyush21
 
Joy And Peace In All Circumstances.pptx
FamilyWorshipCenterD
 
Introductions to artificial intelligence
rakshjain77
 
Public Speakingbjdsbkjfdkjdasnlkdasnlknadslnbsjknsakjscbnkjbncs.pptx
ranazunairriaz1
 
50 Breathtaking WWII Colorized Photos Look Like They Were Taken Yesterday
Ivan Consiglio
 
Mastering the DevOps Certification: CI/CD, Governance & Monitoring Made Simple
shubhamsharma994585
 
Marketing Mix Analysis of Singapore Airlines.pptx
auntorkhastagirpujan
 
Selecting relevant value chain/s for Impactful Development Policies
Francois Stepman
 
GAMABA AWARDEES GINAW BILOG AND SALINTA MONON BY REYMART
purezagambala458
 
Iconic Destinations in India: Explore Heritage and Beauty
dhorashankar
 
Chapter-52-Relationship-between-countries-at-different-levels-of-development-...
dinhminhthu1405
 
DPIC Assingment_1.pptx.pptx for presentation
yashwork2607
 
2025-07-27 Abraham 09 (shared slides).pptx
Dale Wells
 

Some basic FP concepts