Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Learning Functional Programming with JavaScript
Search
Anjana Sofia Vakil
April 24, 2016
Programming
0
840
Learning Functional Programming with JavaScript
Given at JSUnconf 2016 (
http://2016.jsunconf.eu/
)
Anjana Sofia Vakil
April 24, 2016
Tweet
Share
More Decks by Anjana Sofia Vakil
See All by Anjana Sofia Vakil
The Art of Functional Programming
vakila
0
220
First Steps into Functional Programming
vakila
7
2.4k
The Language of Programming
vakila
4
650
Recursion, Iteration, & JavaScript: A love story
vakila
1
440
From Big Band Web App to Serverless Bebop
vakila
0
510
Embracing Constraints
vakila
1
210
Programming across paradigms
vakila
1
740
Immutable data structures for functional JavaScript
vakila
7
1.8k
Functional Programming: What? Why? How?
vakila
1
300
Other Decks in Programming
See All in Programming
Introducing RemoteCompose: break your UI out of the app sandbox.
camaelon
2
540
CloudflareのSandbox SDKを試してみた
syumai
0
140
2025 컴포즈 마법사
jisungbin
0
110
レイトレZ世代に捧ぐ、今からレイトレを始めるための小径
ichi_raven
0
280
DartASTとその活用
sotaatos
2
100
Bakuraku E2E Scenario Test System Architecture #bakuraku_qa_study
teyamagu
PRO
0
710
予防に勝る防御なし(2025年版) - 堅牢なコードを導く様々な設計のヒント / Growing Reliable Code PHP Conference Fukuoka 2025
twada
PRO
36
11k
CSC509 Lecture 11
javiergs
PRO
0
310
乱雑なコードの整理から学ぶ設計の初歩
masuda220
PRO
29
11k
Kotlin 2.2が切り拓く: コンテキストパラメータで書く関数型DSLと新しい依存管理のかたち
knih
0
420
高単価案件で働くための心構え
nullnull
0
130
ノーコードからの脱出 -地獄のデスロード- / Escape from Base44
keisuke69
0
690
Featured
See All Featured
[RailsConf 2023] Rails as a piece of cake
palkan
57
6k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
970
Java REST API Framework Comparison - PWX 2021
mraible
34
9k
A Modern Web Designer's Workflow
chriscoyier
697
190k
Agile that works and the tools we love
rasmusluckow
331
21k
GitHub's CSS Performance
jonrohan
1032
470k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.7k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Transcript
Learning Functional Programming with JS @AnjanaVakil
The Recurse Center https://www.recurse.com/
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 = “Anjana”; var greeting = “Hi,
I’m ”; console.log(greeting + name); => “Hi, I’m Anjana”
Functional: function greet(name) { return “Hi, I’m ” + name;
} greet(“Anjana”); => “Hi, I’m Anjana”
Avoid side effects use “pure” functions
Not pure: var name = “Anjana”; 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 @AnjanaVakil Huge thanks to: JSUnconf organizers
Diversity sponsors The Recurse Center & alums