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
170
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
190
Programming across paradigms
vakila
1
680
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
TCAを用いたAmebaのリアーキテクチャ
dazy
0
210
新宿駅構内を三人称視点で探索してみる
satoshi7190
2
120
CSS Linter による Baseline サポートの仕組み
ryo_manba
1
160
1年目の私に伝えたい!テストコードを怖がらなくなるためのヒント/Tips for not being afraid of test code
push_gawa
1
640
AIプログラミング雑キャッチアップ
yuheinakasaka
19
4.9k
Boos Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
510
複数のAWSアカウントから横断で 利用する Lambda Authorizer の作り方
tc3jp
0
120
Lambdaの監視、できてますか?Datadogを用いてLambdaを見守ろう
nealle
2
520
コミュニティ駆動 AWS CDK ライブラリ「Open Constructs Library」 / community-cdk-library
gotok365
2
250
Jakarta EE meets AI
ivargrimstad
0
530
推しメソッドsource_locationのしくみを探る - はじめてRubyのコードを読んでみた
nobu09
2
340
もう僕は OpenAPI を書きたくない
sgash708
6
1.9k
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.2k
A Tale of Four Properties
chriscoyier
158
23k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.2k
Git: the NoSQL Database
bkeepers
PRO
428
65k
Faster Mobile Websites
deanohume
306
31k
Code Reviewing Like a Champion
maltzj
521
39k
Build The Right Thing And Hit Your Dates
maggiecrowley
34
2.5k
The Invisible Side of Design
smashingmag
299
50k
How GitHub (no longer) Works
holman
314
140k
Gamification - CAS2011
davidbonilla
80
5.2k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Raft: Consensus for Rubyists
vanstee
137
6.8k
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