SlideShare a Scribd company logo
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
Intro to functional programming
Intro to functional programming
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
Intro to functional programming
A Problem
Write a composed function that does
text Capitalization:
“the FORCE is strong with YOU” —>

“The Force Is Strong With You”
Intro to functional programming
Composition
h = f(g(x))
Intro to functional programming
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
Intro to functional programming
Filter
Creates a new array with all
elements that pass the test
implemented by the provided
function
Intro to functional programming
Reduce
Applies a function against an
accumulator and each value of the
array (from left-to-right) to reduce
it to a single value
Intro to functional programming
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

More Related Content

PPTX
Sql(structured query language)
PPTX
PPTX
Syntax & Semantics
PPTX
MLOps.pptx
PPTX
Object Oriented Programming
PDF
Introduction to MS Office.pdf
PPTX
Basics of Object Oriented Programming in Python
PPTX
Semiotics introduction
Sql(structured query language)
Syntax & Semantics
MLOps.pptx
Object Oriented Programming
Introduction to MS Office.pdf
Basics of Object Oriented Programming in Python
Semiotics introduction

What's hot (20)

PDF
Functional Programming Principles & Patterns
PDF
Functional programming
PDF
OOP and FP
PPTX
Introduction to Object Oriented Programming
PPTX
Context free grammar
PPSX
Kotlin Language powerpoint show file
PDF
TypeScript - An Introduction
PPSX
Javascript variables and datatypes
PPTX
[OOP - Lec 18] Static Data Member
PPTX
Functional Programming Fundamentals
PPTX
Regular Expressions in Java
PPTX
OOP Introduction with java programming language
PPTX
Programming Paradigm & Languages
PPTX
structured programming
PPTX
Recursive Function
ODP
Introduction to Shell script
PDF
TypeScript Introduction
PPTX
Lab #2: Introduction to Javascript
PPTX
Introduction to Java -unit-1
PDF
TypeScript: coding JavaScript without the pain
Functional Programming Principles & Patterns
Functional programming
OOP and FP
Introduction to Object Oriented Programming
Context free grammar
Kotlin Language powerpoint show file
TypeScript - An Introduction
Javascript variables and datatypes
[OOP - Lec 18] Static Data Member
Functional Programming Fundamentals
Regular Expressions in Java
OOP Introduction with java programming language
Programming Paradigm & Languages
structured programming
Recursive Function
Introduction to Shell script
TypeScript Introduction
Lab #2: Introduction to Javascript
Introduction to Java -unit-1
TypeScript: coding JavaScript without the pain
Ad

Viewers also liked (19)

PPTX
Reactive Architecture
PPTX
Uses of Cupcakes For Any Occasion in Hyderabad!
PDF
Functional programming for optimization problems in Big Data
PDF
Introduction to Functional Programming
PPT
Introduction To Functional Programming
PDF
那些 Functional Programming 教我的事
PDF
Practical Functional Programming Presentation by Bogdan Hodorog
PDF
Functional Programming Patterns (NDC London 2014)
PDF
Functional Programming Patterns (BuildStuff '14)
PDF
Introduction to Functional Programming with Scala
PDF
Context is Everything - Royi Benyossef
PPTX
Introduction to NserviceBus
PPTX
Ib culture- 3(1)
PDF
Why Do Developers Love Docker?
PDF
CV Ruberto Luca Matteo: ICT SOlution Architect
PPTX
designing distributed scalable and reliable systems
PPTX
Diane Arbus. Fotografía.
PPT
Balanced Scorecard - auch in 2017 immer neu
 
PPTX
Catedral Metropolitana de México.
Reactive Architecture
Uses of Cupcakes For Any Occasion in Hyderabad!
Functional programming for optimization problems in Big Data
Introduction to Functional Programming
Introduction To Functional Programming
那些 Functional Programming 教我的事
Practical Functional Programming Presentation by Bogdan Hodorog
Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (BuildStuff '14)
Introduction to Functional Programming with Scala
Context is Everything - Royi Benyossef
Introduction to NserviceBus
Ib culture- 3(1)
Why Do Developers Love Docker?
CV Ruberto Luca Matteo: ICT SOlution Architect
designing distributed scalable and reliable systems
Diane Arbus. Fotografía.
Balanced Scorecard - auch in 2017 immer neu
 
Catedral Metropolitana de México.
Ad

Similar to Intro to functional programming (20)

PDF
introtofunctionalprogramming2-170301075633.pdf
PDF
Intro to functional programming
PDF
Functional Programming for OO Programmers (part 1)
PDF
Basics of Functional Programming
PDF
Functional JavaScript Fundamentals
PPTX
Intro to Functional Programming
PDF
The Functional Programming Toolkit (NDC Oslo 2019)
ODP
Functional programming
KEY
The Joy Of Functional Programming
PDF
Intro to Functional Programming @ Scala Montreal
PPT
Scala functions
PDF
Functional programming 101
PPTX
Functional programming in python
PDF
Functional programming in python
PPTX
Why functional programming in C# & F#
PPTX
PHP = PHunctional Programming
PDF
Functional Swift
PPTX
Java script function
PPTX
8. Functional Programming_updated(1).pptx
PDF
Fp for the oo programmer
introtofunctionalprogramming2-170301075633.pdf
Intro to functional programming
Functional Programming for OO Programmers (part 1)
Basics of Functional Programming
Functional JavaScript Fundamentals
Intro to Functional Programming
The Functional Programming Toolkit (NDC Oslo 2019)
Functional programming
The Joy Of Functional Programming
Intro to Functional Programming @ Scala Montreal
Scala functions
Functional programming 101
Functional programming in python
Functional programming in python
Why functional programming in C# & F#
PHP = PHunctional Programming
Functional Swift
Java script function
8. Functional Programming_updated(1).pptx
Fp for the oo programmer

More from Assaf Gannon (9)

PPTX
React hooks
PPTX
Serverless in-action
PDF
Serverless meets GraphQL
PDF
Serverless and GraphQL
PDF
Micro frontends
PPTX
Software Architecture Patterns
PPTX
Fullstack workshop
PDF
TabTale Architecture Overview
PDF
From server generated pages to client app in a micro-services world
React hooks
Serverless in-action
Serverless meets GraphQL
Serverless and GraphQL
Micro frontends
Software Architecture Patterns
Fullstack workshop
TabTale Architecture Overview
From server generated pages to client app in a micro-services world

Recently uploaded (20)

PPTX
Introduction to Artificial Intelligence
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPT
Introduction Database Management System for Course Database
PDF
AI in Product Development-omnex systems
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
L1 - Introduction to python Backend.pptx
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PPTX
Transform Your Business with a Software ERP System
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
ai tools demonstartion for schools and inter college
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Introduction to Artificial Intelligence
How Creative Agencies Leverage Project Management Software.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Introduction Database Management System for Course Database
AI in Product Development-omnex systems
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Navsoft: AI-Powered Business Solutions & Custom Software Development
How to Choose the Right IT Partner for Your Business in Malaysia
L1 - Introduction to python Backend.pptx
Adobe Illustrator 28.6 Crack My Vision of Vector Design
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Transform Your Business with a Software ERP System
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
ai tools demonstartion for schools and inter college
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PTS Company Brochure 2025 (1).pdf.......
Operating system designcfffgfgggggggvggggggggg
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises

Intro to functional programming