SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Downloaden Sie, um offline zu lesen
Functional Programming
by Assaf Gannon
Why Do We Need to Change
The Paradigm?!
Object Oriented Programming
is Awesome!
OOP is not cutting
it
Testability
Require lots of mocking
Extensive environmental setup
Hard to maintain as the objects
evolve
Complexity
Tendency to over-design
Re-Use is often complicated and
requires frequent refactoring
Often Objects DON’T represent the
problem correctly
Concurrency
Objects naturally live in a shared
state environment
Multiple Objects in a shared state
environment handle concurrency
poorly
Enter Functional
Programming!
Why Functional?!
Mathematical approach to solving
problems
More simple and less abstract
Easy Reuse, Test and handle
Concurrency
FP Principles
Purity
Immutability
High Order
Composition
Currying
Purity
Pure Function
Pure functions act on their
parameters
Are not efficient if not returning
anything
Will always produce the same output
for the given parameters
Have NO side affects
Pure Function
ImPure Functions
Immutability
There are no “Variables” in Functional
programming - all “variables” should
be considered as constants
When Do we mutate
variables?
Short living “local” variables
Loop flow structures
State objects
Javascript is Not a
pure functional
programming
language - it allows
for mutable
structures. We need
to “tweak” it…
Simple Immutable
tweaks
arr.push(val) —> [].concat(arr, val)
obj[‘key’] = val —> Object.assign({key: val}, obj)
ImmutableObj = Object.freeze(obj) 





** Object assign is limited to shallow cloning and
may produce strange outcomes.

see: 

https://developer.mozilla.org/en-US/docs/Web/
JavaScript/Reference/Global_Objects/Object/create
For “real” projects use an immutable
library such as ImmutableJS or
seamless-immutable
Higher Order Functions
In Functional Programming, a
function is a first-class citizen of the
language. In other words:

A function is just another value
Higher Order
Functions
Take functions as parameters
Return functions
Both
A closure is a function’s scope that’s
kept alive by a reference to that
function.
Function Composition
newFunc = f(g(x))
Application of one function to the
result of another to produce a third
function
A Problem
Write a composed function that does
text Capitalization:
“the FORCE is strong with YOU” —>

“The Force Is Strong With You”
Composition
h = f(g(x))
Enhanced
Capitalize Problem
I want to ignore a list of words:

a, is, for, etc. so:



“the FORCE is strong with YOU” —>

“The Fore is Strong With You”
This sucks…
Currying
A Curried Function is a function that
only takes a single parameter at a
time.
Much better :)
Common Functional
Functions
Map
Creates a new array with the results
of calling a provided function on
every element in the array
Filter
Creates a new array with all
elements that pass the test
implemented by the provided
function
Reduce
Applies a function against an
accumulator and each value of the
array (from left-to-right) to reduce
it to a single value
Summary
Use “Pure” functions to create predictable &
stable code
Use Immutable structs to avoid side effects
Compose complex functionality from
simple building blocks
Use currying for simple composition
Avoid “boilerplate” code and loops by using
functional functions

Weitere ähnliche Inhalte

Was ist angesagt?

JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
Jussi Pohjolainen
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
Introduction to object oriented programming
Introduction to object oriented programmingIntroduction to object oriented programming
Introduction to object oriented programming
Abzetdin Adamov
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
imypraz
 

Was ist angesagt? (20)

JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Object Oriented Programming Concepts for beginners
Object Oriented Programming Concepts for beginners Object Oriented Programming Concepts for beginners
Object Oriented Programming Concepts for beginners
 
Java Notes
Java NotesJava Notes
Java Notes
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Introduction to object oriented programming
Introduction to object oriented programmingIntroduction to object oriented programming
Introduction to object oriented programming
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
enums
enumsenums
enums
 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
C# Async Await
C# Async AwaitC# Async Await
C# Async Await
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Generics C#
Generics C#Generics C#
Generics C#
 

Andere mochten auch

Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
Andreas Pauley
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
pramode_ce
 

Andere mochten auch (19)

Reactive Architecture
Reactive ArchitectureReactive Architecture
Reactive Architecture
 
Uses of Cupcakes For Any Occasion in Hyderabad!
 Uses of Cupcakes For Any Occasion in Hyderabad! Uses of Cupcakes For Any Occasion in Hyderabad!
Uses of Cupcakes For Any Occasion in Hyderabad!
 
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
 
那些 Functional Programming 教我的事
那些 Functional Programming 教我的事那些 Functional Programming 教我的事
那些 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 Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)
 
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
 
Context is Everything - Royi Benyossef
Context is Everything - Royi Benyossef Context is Everything - Royi Benyossef
Context is Everything - Royi Benyossef
 
Introduction to NserviceBus
Introduction to NserviceBusIntroduction to NserviceBus
Introduction to NserviceBus
 
Ib culture- 3(1)
Ib culture- 3(1)Ib culture- 3(1)
Ib culture- 3(1)
 
Why Do Developers Love Docker?
Why Do Developers Love Docker?Why Do Developers Love Docker?
Why Do Developers Love Docker?
 
CV Ruberto Luca Matteo: ICT SOlution Architect
CV Ruberto Luca Matteo: ICT SOlution ArchitectCV Ruberto Luca Matteo: ICT SOlution Architect
CV Ruberto Luca Matteo: ICT SOlution Architect
 
designing distributed scalable and reliable systems
designing distributed scalable and reliable systemsdesigning distributed scalable and reliable systems
designing distributed scalable and reliable systems
 
Diane Arbus. Fotografía.
Diane Arbus. Fotografía.Diane Arbus. Fotografía.
Diane Arbus. Fotografía.
 
Balanced Scorecard - auch in 2017 immer neu
Balanced Scorecard - auch in 2017 immer neuBalanced Scorecard - auch in 2017 immer neu
Balanced Scorecard - auch in 2017 immer neu
 
Catedral Metropolitana de México.
Catedral Metropolitana de México.Catedral Metropolitana de México.
Catedral Metropolitana de México.
 

Ähnlich wie Intro to functional programming

introtofunctionalprogramming2-170301075633.pdf
introtofunctionalprogramming2-170301075633.pdfintrotofunctionalprogramming2-170301075633.pdf
introtofunctionalprogramming2-170301075633.pdf
RodulfoGabrito
 

Ähnlich wie Intro to functional programming (20)

introtofunctionalprogramming2-170301075633.pdf
introtofunctionalprogramming2-170301075633.pdfintrotofunctionalprogramming2-170301075633.pdf
introtofunctionalprogramming2-170301075633.pdf
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programming
 
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)
 
Basics of Functional Programming
Basics of Functional ProgrammingBasics of Functional Programming
Basics of Functional Programming
 
Functional JavaScript Fundamentals
Functional JavaScript FundamentalsFunctional JavaScript Fundamentals
Functional JavaScript Fundamentals
 
Intro to Functional Programming
Intro to Functional ProgrammingIntro to Functional Programming
Intro to Functional Programming
 
The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
The Joy Of Functional Programming
The Joy Of Functional ProgrammingThe Joy Of Functional Programming
The Joy Of Functional Programming
 
Intro to Functional Programming @ Scala Montreal
Intro to Functional Programming @ Scala MontrealIntro to Functional Programming @ Scala Montreal
Intro to Functional Programming @ Scala Montreal
 
Scala functions
Scala functionsScala functions
Scala functions
 
Functional programming 101
Functional programming 101Functional programming 101
Functional programming 101
 
Functional programming in python
Functional programming in pythonFunctional programming in python
Functional programming in python
 
Functional programming in python
Functional programming in pythonFunctional programming in python
Functional programming in python
 
Why functional programming in C# & F#
Why functional programming in C# & F#Why functional programming in C# & F#
Why functional programming in C# & F#
 
PHP = PHunctional Programming
PHP = PHunctional ProgrammingPHP = PHunctional Programming
PHP = PHunctional Programming
 
Functional Swift
Functional SwiftFunctional Swift
Functional Swift
 
Java script function
Java script functionJava script function
Java script function
 
Fp for the oo programmer
Fp for the oo programmerFp for the oo programmer
Fp for the oo programmer
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programming
 

Mehr von Assaf Gannon

From server generated pages to client app in a micro-services world
From server generated pages to client app in a micro-services worldFrom server generated pages to client app in a micro-services world
From server generated pages to client app in a micro-services world
Assaf Gannon
 

Mehr von Assaf Gannon (9)

React hooks
React hooksReact hooks
React hooks
 
Serverless in-action
Serverless in-actionServerless in-action
Serverless in-action
 
Serverless meets GraphQL
Serverless meets GraphQLServerless meets GraphQL
Serverless meets GraphQL
 
Serverless and GraphQL
Serverless and GraphQLServerless and GraphQL
Serverless and GraphQL
 
Micro frontends
Micro frontendsMicro frontends
Micro frontends
 
Software Architecture Patterns
Software Architecture PatternsSoftware Architecture Patterns
Software Architecture Patterns
 
Fullstack workshop
Fullstack workshopFullstack workshop
Fullstack workshop
 
TabTale Architecture Overview
TabTale Architecture OverviewTabTale Architecture Overview
TabTale Architecture Overview
 
From server generated pages to client app in a micro-services world
From server generated pages to client app in a micro-services worldFrom server generated pages to client app in a micro-services world
From server generated pages to client app in a micro-services world
 

Kürzlich hochgeladen

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
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
+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
 

Kürzlich hochgeladen (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
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 ...
 
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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
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 🔝✔️✔️
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
+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...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
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
 
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-...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
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 🔝✔️✔️
 
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
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 

Intro to functional programming