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
850
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
240
First Steps into Functional Programming
vakila
7
2.4k
The Language of Programming
vakila
4
700
Recursion, Iteration, & JavaScript: A love story
vakila
1
460
From Big Band Web App to Serverless Bebop
vakila
0
530
Embracing Constraints
vakila
1
220
Programming across paradigms
vakila
1
750
Immutable data structures for functional JavaScript
vakila
7
1.8k
Functional Programming: What? Why? How?
vakila
1
310
Other Decks in Programming
See All in Programming
Claude Code の Skill で複雑な既存仕様をすっきり整理しよう
yuichirokato
1
370
AIとペアプロして処理時間を97%削減した話 #pyconshizu
kashewnuts
1
230
TipKitTips
ktcryomm
0
160
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
16
3.1k
GC言語のWasm化とComponent Modelサポートの実践と課題 - Scalaの場合
tanishiking
0
110
CSC307 Lecture 15
javiergs
PRO
0
240
Swift ConcurrencyでよりSwiftyに
yuukiw00w
0
260
守る「だけ」の優しいEMを抜けて、 事業とチームを両方見る視点を身につけた話
maroon8021
3
840
encoding/json/v2のUnmarshalはこう変わった:内部実装で見る設計改善
kurakura0916
0
410
CSC307 Lecture 14
javiergs
PRO
0
470
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
430
maplibre-gl-layers - 地図に移動体たくさん表示したい
kekyo
PRO
0
260
Featured
See All Featured
Design in an AI World
tapps
0
170
How to Think Like a Performance Engineer
csswizardry
28
2.5k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
680
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
450
How Software Deployment tools have changed in the past 20 years
geshan
0
32k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
220
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.4k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
390
Designing for Performance
lara
611
70k
Test your architecture with Archunit
thirion
1
2.2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.4k
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