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
870
0
Share
Learning Functional Programming with JavaScript
Given at JSUnconf 2016 (
http://2016.jsunconf.eu/
)
Anjana Sofia Vakil
April 24, 2016
More Decks by Anjana Sofia Vakil
See All by Anjana Sofia Vakil
The Art of Functional Programming
vakila
0
260
First Steps into Functional Programming
vakila
7
2.5k
The Language of Programming
vakila
4
710
Recursion, Iteration, & JavaScript: A love story
vakila
1
470
From Big Band Web App to Serverless Bebop
vakila
0
540
Embracing Constraints
vakila
1
240
Programming across paradigms
vakila
1
770
Immutable data structures for functional JavaScript
vakila
7
1.8k
Functional Programming: What? Why? How?
vakila
1
330
Other Decks in Programming
See All in Programming
AIとRubyの静的型付け
ukin0k0
0
130
AI Agent と正しく分析するための環境作り
yoshyum
3
610
inferと仲良くなる10分間
ryokatsuse
1
260
Hive Metastoreを通して学ぶIceberg REST Catalog ― 仕様から実装まで
okumin
0
280
Inspired By RubyKaigi (EN)
atzzcokek
0
110
1人1案件のプロダクトエンジニア時代に、"プロセス監督"としてチャレンジしたこと
non0113
0
330
要はバランスからの卒業 #yumemi_grow
kajitack
0
200
AlarmKitで明後日起きれるアラームアプリを作る
trickart
0
150
oxlintはeslint/typescript-eslintを置き換えられるのか
shomafujita
2
250
分析エージェント精度向上における データアナリストの役割
oura_shoya
0
120
開発とはなにか、Essenceカーネルで見えるもの
ukin0k0
0
210
LLM Plugin for Node-REDの利用方法と開発について
404background
0
120
Featured
See All Featured
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
270
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
200
GraphQLとの向き合い方2022年版
quramy
50
15k
Prompt Engineering for Job Search
mfonobong
0
320
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
510
The Language of Interfaces
destraynor
162
26k
AI: The stuff that nobody shows you
jnunemaker
PRO
7
660
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
190
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
How to make the Groovebox
asonas
2
2.2k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
420
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