Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
forループを越えて / beyond for loop
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Shunsuke Watanabe
October 12, 2018
Programming
620
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
forループを越えて / beyond for loop
#SurviveJS05 発表資料
高階関数を活用してコードを読みやすくする話です
Shunsuke Watanabe
October 12, 2018
Transcript
32 slides
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!
More Decks by Shunsuke Watanabe
See All by Shunsuke Watanabe
いますぐ {id: number;} をやめろ
craftgear
1
410
Reactハンズオン 01 入門編 コード部分抜粋 / React Handson 01 components (excerpt)
craftgear
1
640
Reactハンズオン 02 redux編 コード部分抜粋 / React Handson 02 redux (excerpt)
craftgear
0
640
Reactハンズオン 01 入門編 コード部分抜粋 / React Handson 01 components (excerpt)
craftgear
0
770
Reactで作るDrupalサイト
craftgear
0
540
大阪Node学園 七時限目 「ゼロからはじめるnode.js」
craftgear
1
430
大阪Node学園 六時限目 「generator小咄」
craftgear
1
360
大阪Node学園四時限目 "This crazy testless world"
craftgear
1
350
Other Decks in Programming
See All in Programming
AI時代のシニアエンジニアとは
yosuke_furukawa
PRO
15
12k
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
360
コード生成時代のAPI定義を支えるRequest Spec移行
pvcresin
0
290
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
430
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
140
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
260
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
190
Proxmox x Talos Linux x Terraform で実現するなんかいい感じの Kubernetes クラスタ / A Sleek Kubernetes Cluster Powered by Proxmox, Talos Linux, and Terraform
nnaka2992
0
260
RaspberryPi 5で軽くはじめるk3sとtailscaleを用いたホームサーバー構築 (1)
nasum
0
410
AI Augmentation Techniques with Liberty
ivargrimstad
1
520
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
190
SODA - FACT BOOK(JP)
sodainc
1
40k
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
340
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.7k
GitHub's CSS Performance
jonrohan
1033
470k
Paper Plane (Part 1)
katiecoart
PRO
3
12k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
1k
The SEO Collaboration Effect
kristinabergwall1
1
620
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
470
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Un-Boring Meetings
codingconduct
0
500
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Documentation Writing (for coders)
carmenintech
77
5.6k