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
820
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
180
First Steps into Functional Programming
vakila
7
2.3k
The Language of Programming
vakila
4
560
Recursion, Iteration, & JavaScript: A love story
vakila
1
420
From Big Band Web App to Serverless Bebop
vakila
0
470
Embracing Constraints
vakila
1
200
Programming across paradigms
vakila
1
690
Immutable data structures for functional JavaScript
vakila
7
1.7k
Functional Programming: What? Why? How?
vakila
1
260
Other Decks in Programming
See All in Programming
PHP で学ぶ OAuth 入門
azuki
1
210
個人開発の学生アプリが企業譲渡されるまで
akidon0000
0
950
fieldalignmentから見るGoの構造体
kuro_kurorrr
0
110
音声プラットフォームのアーキテクチャ変遷から学ぶ、クラウドネイティブなバッチ処理 (20250422_CNDS2025_Batch_Architecture)
thousanda
0
290
Laravel × Clean Architecture
bumptakayuki
PRO
0
110
ComposeでのPicture in Picture
takathemax
0
120
実践Webフロントパフォーマンスチューニング
cp20
22
4.9k
「影響が少ない」を自分の目でみてみる
o0h
PRO
2
1.2k
「理解」を重視したAI活用開発
fast_doctor
0
190
Amazon CloudWatchの地味だけど強力な機能紹介!
itotsum
0
180
趣味全開のAITuber開発
kokushin
0
200
タイムゾーンの奥地は思ったよりも闇深いかもしれない
suguruooki
1
720
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Adopting Sorbet at Scale
ufuk
76
9.3k
Docker and Python
trallard
44
3.3k
Fontdeck: Realign not Redesign
paulrobertlloyd
83
5.5k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Java REST API Framework Comparison - PWX 2021
mraible
30
8.5k
GraphQLとの向き合い方2022年版
quramy
46
14k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.1k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.2k
Rebuilding a faster, lazier Slack
samanthasiow
80
8.9k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
The Language of Interfaces
destraynor
157
25k
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