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
590
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
More Decks by Shunsuke Watanabe
See All by Shunsuke Watanabe
いますぐ {id: number;} をやめろ
craftgear
1
380
Reactハンズオン 01 入門編 コード部分抜粋 / React Handson 01 components (excerpt)
craftgear
1
610
Reactハンズオン 02 redux編 コード部分抜粋 / React Handson 02 redux (excerpt)
craftgear
0
600
Reactハンズオン 01 入門編 コード部分抜粋 / React Handson 01 components (excerpt)
craftgear
0
730
Reactで作るDrupalサイト
craftgear
0
510
大阪Node学園 七時限目 「ゼロからはじめるnode.js」
craftgear
1
430
大阪Node学園 六時限目 「generator小咄」
craftgear
1
350
大阪Node学園四時限目 "This crazy testless world"
craftgear
1
350
Other Decks in Programming
See All in Programming
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.6k
Prismを使った型安全な暗号化_関数型まつり2026
_fhhmm
0
150
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
160
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
1k
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
9.3k
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.8k
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
110
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
1
220
GitHubCopilotCLIのスラッシュコマンドを自作してみる
htkym
0
110
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
200
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
0
120
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
170
Featured
See All Featured
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
500
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
640
Making Projects Easy
brettharned
120
6.7k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
RailsConf 2023
tenderlove
30
1.5k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
270
GraphQLとの向き合い方2022年版
quramy
50
15k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
Ethics towards AI in product and experience design
skipperchong
2
330
Code Reviewing Like a Champion
maltzj
528
40k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
Marketing to machines
jonoalderson
1
5.6k
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!