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
190
First Steps into Functional Programming
vakila
7
2.3k
The Language of Programming
vakila
4
580
Recursion, Iteration, & JavaScript: A love story
vakila
1
430
From Big Band Web App to Serverless Bebop
vakila
0
490
Embracing Constraints
vakila
1
200
Programming across paradigms
vakila
1
720
Immutable data structures for functional JavaScript
vakila
7
1.7k
Functional Programming: What? Why? How?
vakila
1
280
Other Decks in Programming
See All in Programming
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
16
3.1k
Bytecode Manipulation 으로 생산성 높이기
bigstark
2
370
生成AIで日々のエラー調査を進めたい
yuyaabo
0
640
設計やレビューに悩んでいるPHPerに贈る、クリーンなオブジェクト設計の指針たち
panda_program
6
1.2k
データの民主化を支える、透明性のあるデータ利活用への挑戦 2025-06-25 Database Engineering Meetup#7
y_ken
0
310
[初登壇@jAZUG]アプリ開発者が気になるGoogleCloud/Azure+wasm/wasi
asaringo
0
130
つよそうにふるまい、つよい成果を出すのなら、つよいのかもしれない
irof
1
300
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
120
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
170
5つのアンチパターンから学ぶLT設計
narihara
1
110
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
250
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
470
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
56
9.4k
Adopting Sorbet at Scale
ufuk
77
9.4k
Making Projects Easy
brettharned
116
6.3k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
GraphQLとの向き合い方2022年版
quramy
47
14k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Code Reviewing Like a Champion
maltzj
524
40k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
How to Think Like a Performance Engineer
csswizardry
24
1.7k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Git: the NoSQL Database
bkeepers
PRO
430
65k
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