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
forループを越えて / beyond for loop
Search
Shunsuke Watanabe
October 12, 2018
Programming
0
250
forループを越えて / beyond for loop
#SurviveJS05 発表資料
高階関数を活用してコードを読みやすくする話です
Shunsuke Watanabe
October 12, 2018
Tweet
Share
More Decks by Shunsuke Watanabe
See All by Shunsuke Watanabe
いますぐ {id: number;} をやめろ
craftgear
1
24
Reactハンズオン 01 入門編 コード部分抜粋 / React Handson 01 components (excerpt)
craftgear
1
330
Reactハンズオン 02 redux編 コード部分抜粋 / React Handson 02 redux (excerpt)
craftgear
0
330
Reactハンズオン 01 入門編 コード部分抜粋 / React Handson 01 components (excerpt)
craftgear
0
290
Reactで作るDrupalサイト
craftgear
0
180
大阪Node学園 七時限目 「ゼロからはじめるnode.js」
craftgear
1
390
大阪Node学園 六時限目 「generator小咄」
craftgear
1
280
大阪Node学園四時限目 "This crazy testless world"
craftgear
1
300
Other Decks in Programming
See All in Programming
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
900
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
100
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
290
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
860
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
920
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
100
Ethereum_.pdf
nekomatu
0
460
受け取る人から提供する人になるということ
little_rubyist
0
230
【Kaigi on Rails 2024】YOUTRUST スポンサーLT
krpk1900
1
330
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
222
8.9k
We Have a Design System, Now What?
morganepeng
50
7.2k
It's Worth the Effort
3n
183
27k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Writing Fast Ruby
sferik
627
61k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Unsuck your backbone
ammeep
668
57k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Transcript
forϧʔϓΛ͑ͯ ลढ़ี ˏcraftgear
ߴ֊ؔͬͯ ͝ଘͰ͔͢ʁ
ߴ֊ؔͱ ͨͱ͑ɺ
ؔΛҾʹऔΔ ؔ $('#button').click( e => { console.log(e); } );
ؔΛΓͱ͠ ͯฦؔ͢ const createCounter = () => { var number
= 0; return () => { number++; return number; }; }
Array.map(fn)
forϧʔϓͰͳ ͯ͘mapϝιο υΛ͏ཧ༝
ίʔυ ͷ ҙਤ
const a = [1,2,3].map(fn)
Γaͷܕ ྻͰɺ ཁૉ̏
ྻͷ֤ཁૉ ʹରͯ͠fnΛ ࣮ߦ͍ͯ͠Δ
ԿΛΓ͍ͨ ͔fnͷதΛ ಡΊΘ͔Δ
Θ͔Γ͍͢ ί ʔ υ ɺॏཁɻ
ϝϯς͕༰қ ฏͳίʔυ ϨϏϡʔ
fnΛΓग़ ͯ͠ςετ
࣭ ্
UIߏங ʹศར
const dummyTodos = [ { id: 1, title: 'aaaa', done:
true }, { id: 2, title: 'aaaa', done: false }, ]; const TodoList = ({ todos }) => ( <div> {todos.map(todo => ( <TodoItem key={todo.id} {...todo} /> ))} </div> );
map͚ͩ ͡Όͳ͍
map(f) filter(f) reduce(f, init) forEach(f) ྻ [n] [n] [n] [n]
Γ [n] [<= n] initͱಉܕ ͳ͠
some(f) every(f) findIndex(f) find(f) ྻ [n] [n] [n] [n] Γ
ਅِ ਅِ ཁૉҰͭ
༻্ͷҙ
filterʹ͢fn͕ฦ͢ ਅِͰ͋Δ͜ͱ -1falseʹͳΒͳ͍
[].some [].every ৗʹtrue ʮۭڏʹਅʯ
ඇಉظॲཧ Promise.all()Ͱ
reduce ΄Ͳ΄Ͳʹ
chainingͱ compositionͰ ֦͕Δੈք
const double = v => v * 2 const over5
= v => v > 5 const a = [1,2,3] .map(double) .filter(over5)
import * as R from 'ramda'; const doubleOver5 = R.compose(
R.filter(over5), R.map(double) );
const b = doubleOver5([2, 3, 4]); const c = doubleOver5(
{a: 1, b: 2, c: 3} );
࣮ԋ
Thank You!