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
880
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
290
First Steps into Functional Programming
vakila
7
2.5k
The Language of Programming
vakila
4
740
Recursion, Iteration, & JavaScript: A love story
vakila
1
490
From Big Band Web App to Serverless Bebop
vakila
0
550
Embracing Constraints
vakila
1
250
Programming across paradigms
vakila
1
780
Immutable data structures for functional JavaScript
vakila
7
1.9k
Functional Programming: What? Why? How?
vakila
1
340
Other Decks in Programming
See All in Programming
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
540
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
130
yield再入門 #phpcon
o0h
PRO
0
990
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
210
AIが無かった頃の素敵な出会いの話
codmoninc
1
400
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
300
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
370
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.9k
今さら聞けない .NET CLI
htkym
0
180
Android CLI
fornewid
0
210
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
1
750
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
110
Featured
See All Featured
Designing Experiences People Love
moore
143
24k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.1k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
440
Fireside Chat
paigeccino
42
4k
Everyday Curiosity
cassininazir
0
270
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Building AI with AI
inesmontani
PRO
1
1.1k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
400
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
How GitHub (no longer) Works
holman
316
150k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
530
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