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
800
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
170
First Steps into Functional Programming
vakila
7
2.3k
The Language of Programming
vakila
4
520
Recursion, Iteration, & JavaScript: A love story
vakila
1
410
From Big Band Web App to Serverless Bebop
vakila
0
460
Embracing Constraints
vakila
1
190
Programming across paradigms
vakila
1
670
Immutable data structures for functional JavaScript
vakila
7
1.6k
Functional Programming: What? Why? How?
vakila
1
240
Other Decks in Programming
See All in Programming
Scaling your build logic
antalmonori
1
100
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
630
ATDDで素早く安定した デリバリを実現しよう!
tonnsama
1
1.9k
Lookerは可視化だけじゃない。UIコンポーネントもあるんだ!
ymd65536
1
130
歴史と現在から考えるスケーラブルなソフトウェア開発のプラクティス
i10416
0
300
Package Traits
ikesyo
1
210
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
4
1.1k
Rubyでつくるパケットキャプチャツール
ydah
0
170
Simple組み合わせ村から大都会Railsにやってきた俺は / Coming to Rails from the Simple
moznion
3
2.2k
Androidアプリの One Experience リリース
nein37
0
1.2k
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
7
1.4k
ISUCON14感想戦で85万点まで頑張ってみた
ponyo877
1
590
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
137
6.7k
Building Applications with DynamoDB
mza
93
6.2k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5.1k
Speed Design
sergeychernyshev
25
740
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Building Your Own Lightsaber
phodgson
104
6.2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
192
16k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
How to Ace a Technical Interview
jacobian
276
23k
RailsConf 2023
tenderlove
29
970
How to train your dragon (web standard)
notwaldorf
89
5.8k
A Modern Web Designer's Workflow
chriscoyier
693
190k
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