SlideShare a Scribd company logo
Learning Functional
Programming with JS
@RajohnsonAndry
What is functional programming?
What is functional programming?
a programming paradigm
What is functional programming?
a coding style
What is functional programming?
a mindset
What is functional programming?
a sexy, buzz-wordy trend
Why functional JavaScript?
Why functional JavaScript?
object-oriented JS gets tricky
(prototypes? this?!?)
Why functional JavaScript?
safer, easier to debug/maintain
Why functional JavaScript?
established community
OK, let’s do it!
OK, let’s do it!
...how?
Do everything with functions
input -> output
Not functional:
var name = “Andry”;
var greeting = “Hi, I’m ”;
console.log(greeting + name);
=> “Hi, I’m Andry”
Functional:
function greet(name) {
return “Hi, I’m ” + name;
}
greet(“Andry”);
=> “Hi, I’m Andry”
Avoid side effects
use “pure” functions
Not pure:
var name = “Andry”;
function greet() {
console.log(“Hi, I’m ” + name);
}
Pure:
function greet(name) { return
“Hi, I’m ” + name;
}
Use higher-order functions
functions can be inputs/outputs
function makeAdjectifier(adjective) {
return function (string) {
return adjective + “ ” + string;
};
}
var coolifier = makeAdjectifier(“cool”);
coolifier(“conference”);
=> “cool conference”
Don’t iterate
use map, reduce, filter
http://www.datasciencecentral.com/forum/topics/what-is-map-reduce
Avoid mutability
use immutable data
Mutation (bad!):
var rooms = [“H1”, “H2”, “H3”];
rooms[2] = “H4”;
rooms;
=> ["H1", "H2", "H4"]
No mutation (good!):
var rooms = [“H1”, “H2”, “H3”];
var newRooms = rooms.map(function (rm) { if (rm
== “H3”) { return “H4”; }
else { return rm; }
});
newRooms; => ["H1", "H2", "H4"]
rooms; => ["H1", "H2", "H3"]
Persistent data structures
for efficient immutability
Mori, Immutable.js
Ready to try it out?
FP libraries for JS
 Mori (http://swannodette.github.io/mori/)
 Immutable.js (https://facebook.github.
io/immutable-js/)
 Underscore (http://underscorejs.org/)
 Lodash (https://lodash.com/)
 Ramda (http://ramdajs.com/)
 ...and more!
Want to learn more?
“An introduction to functional
programming”
by Mary Rose Cook
https://codewords.recurse.com/issues/one/an-introduction-to-functional-programming
Thanks for listening!
I’m @RajohnsonAndry

More Related Content

PDF
Mume JQueryMobile Intro
PDF
Cross-platform development in the context of mobile web
PDF
Jquery, write less do more by weLaika
PPT
JavaScript on Rails 튜토리얼
PDF
20111014 mu me_j_querymobile
PDF
Railsbridge javascript
KEY
Intro to jQuery for Drupal
PDF
Intro to jquery
Mume JQueryMobile Intro
Cross-platform development in the context of mobile web
Jquery, write less do more by weLaika
JavaScript on Rails 튜토리얼
20111014 mu me_j_querymobile
Railsbridge javascript
Intro to jQuery for Drupal
Intro to jquery

Similar to Functionnal programming (20)

PDF
379008-rc217-functionalprogramming
PPTX
Introduction to functional programming with JavaScript
PDF
Functional programing in Javascript (lite intro)
PPTX
Functional Programming in Javascript - IL Tech Talks week
PPTX
WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD?
PDF
Functional Programming with Javascript
PPTX
Why Functional Programming So Hard?
PDF
Functional Programming: An Introduction
PPTX
A Skeptics guide to functional style javascript
PDF
Functional Programming
ODP
Functional programming
PDF
Make javascript great again | Odessa Frontend Meetup #8
PDF
Functional JavaScript Fundamentals
PPTX
Thinking Functionally with JavaScript
PDF
Functional Programming with JavaScript
PDF
Intro to functional programming
PPTX
Functional programming with Immutable .JS
PPTX
Functional Programming in JavaScript by Luis Atencio
PPTX
Declarative JavaScript concepts and implemetation
PDF
introtofunctionalprogramming2-170301075633.pdf
379008-rc217-functionalprogramming
Introduction to functional programming with JavaScript
Functional programing in Javascript (lite intro)
Functional Programming in Javascript - IL Tech Talks week
WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD?
Functional Programming with Javascript
Why Functional Programming So Hard?
Functional Programming: An Introduction
A Skeptics guide to functional style javascript
Functional Programming
Functional programming
Make javascript great again | Odessa Frontend Meetup #8
Functional JavaScript Fundamentals
Thinking Functionally with JavaScript
Functional Programming with JavaScript
Intro to functional programming
Functional programming with Immutable .JS
Functional Programming in JavaScript by Luis Atencio
Declarative JavaScript concepts and implemetation
introtofunctionalprogramming2-170301075633.pdf
Ad

More from AndryRajohnson (7)

PPTX
Meetup Javascript for beginner
PPTX
React 101
PPTX
Git et github (1)
PPTX
2h landing page
PPT
Java script the weird part (PART I )
PPTX
Modern web app with REACT
PDF
Coder son site web
Meetup Javascript for beginner
React 101
Git et github (1)
2h landing page
Java script the weird part (PART I )
Modern web app with REACT
Coder son site web
Ad

Recently uploaded (20)

PPTX
L1 - Introduction to python Backend.pptx
PDF
System and Network Administraation Chapter 3
PPTX
Transform Your Business with a Software ERP System
PDF
System and Network Administration Chapter 2
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PDF
top salesforce developer skills in 2025.pdf
PPTX
ISO 45001 Occupational Health and Safety Management System
PPTX
Safe Confined Space Entry Monitoring_ Singapore Experts.pptx
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Introduction to Artificial Intelligence
PDF
Digital Strategies for Manufacturing Companies
PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
PPTX
Materi-Enum-and-Record-Data-Type (1).pptx
PPTX
Presentation of Computer CLASS 2 .pptx
PPTX
CRUISE TICKETING SYSTEM | CRUISE RESERVATION SOFTWARE
PPT
JAVA ppt tutorial basics to learn java programming
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
L1 - Introduction to python Backend.pptx
System and Network Administraation Chapter 3
Transform Your Business with a Software ERP System
System and Network Administration Chapter 2
Materi_Pemrograman_Komputer-Looping.pptx
top salesforce developer skills in 2025.pdf
ISO 45001 Occupational Health and Safety Management System
Safe Confined Space Entry Monitoring_ Singapore Experts.pptx
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
How to Choose the Right IT Partner for Your Business in Malaysia
Introduction to Artificial Intelligence
Digital Strategies for Manufacturing Companies
A REACT POMODORO TIMER WEB APPLICATION.pdf
Materi-Enum-and-Record-Data-Type (1).pptx
Presentation of Computer CLASS 2 .pptx
CRUISE TICKETING SYSTEM | CRUISE RESERVATION SOFTWARE
JAVA ppt tutorial basics to learn java programming
Understanding Forklifts - TECH EHS Solution
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...

Functionnal programming