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
810
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
550
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.6k
Functional Programming: What? Why? How?
vakila
1
250
Other Decks in Programming
See All in Programming
goにおける コネクションプールの仕組み を軽く掘って見た
aronokuyama
0
140
20250326_生成AIによる_レビュー承認システムの実現.pdf
takahiromatsui
17
5.8k
PHPer's Guide to Daemon Crafting Taming and Summoning
uzulla
2
1.1k
CTFのWebにおける⾼難易度問題について
hamayanhamayan
1
1k
Coding Experience Cpp vs Csharp - meetup app osaka@9
harukasao
0
170
アーキテクトと美学 / Architecture and Aesthetics
nrslib
12
3.2k
小さく段階的リリースすることで深夜メンテを回避する
mkmk884
2
130
本当だってば!俺もTRICK 2022に入賞してたんだってば!
jinroq
0
260
snacks.nvim内のセットアップ不要なプラグインを紹介 / introduce_snacks_nvim
uhooi
0
360
コンテナでLambdaをデプロイするときに知っておきたかったこと
_takahash
0
160
マルチアカウント環境での、そこまでがんばらない RI/SP 運用設計
wa6sn
0
640
Kubernetesで実現できるPlatform Engineering の現在地
nwiizo
3
1.8k
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
227
22k
Large-scale JavaScript Application Architecture
addyosmani
511
110k
Producing Creativity
orderedlist
PRO
344
40k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
12
620
GraphQLの誤解/rethinking-graphql
sonatard
70
10k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
12k
Raft: Consensus for Rubyists
vanstee
137
6.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.2k
Become a Pro
speakerdeck
PRO
27
5.2k
Mobile First: as difficult as doing things right
swwweet
223
9.5k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
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