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
Ramdaで手軽に関数型言語を始めよう
Search
kaidouji85
May 03, 2016
Technology
0
310
Ramdaで手軽に関数型言語を始めよう
初夏のJavaScript祭2016のLTスライドです。
kaidouji85
May 03, 2016
Tweet
Share
More Decks by kaidouji85
See All by kaidouji85
一発芸!!なんちゃってローカライズ
kaidouji85
0
18
AWSだけでネット対戦できるブラウザゲームを作った話
kaidouji85
0
34
GitHub CopilotでJavaScript開発効率を爆上げする
kaidouji85
0
63
Serverless + Fargate構成で継続的デリバリーの速度を劇的に改善した話
kaidouji85
0
760
サーバーレスアーキテクチャこそ"ヘキサゴナルアーキテクチャ"
kaidouji85
0
61
サーバーレスでターンベース制のネット対戦ゲームを作った話
kaidouji85
0
510
CDKで構築したFargateのデプロイ時間を改善した話
kaidouji85
2
450
ブラウザゲームで視聴者参加型のゲーム配信
kaidouji85
0
260
JSだけでバックエンド環境構築、IaC、自動デプロイまでやってみた話
kaidouji85
0
320
Other Decks in Technology
See All in Technology
Fanstaの1年を大解剖! 一人SREはどこまでできるのか!?
syossan27
2
350
終了の危機にあった15年続くWebサービスを全力で存続させる - phpcon2024
yositosi
28
24k
3年でバックエンドエンジニアが5倍に増えても破綻しなかったアーキテクチャ そして、これから / Software architecture that scales even with a 5x increase in backend engineers in 3 years
euglena1215
11
4.1k
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
230
ソフトウェア開発における「パーフェクトな意思決定」/Perfect Decision-Making in Software Development
yayoi_dd
2
2.4k
Web APIをなぜつくるのか
mikanichinose
0
1k
Wantedly での Datadog 活用事例
bgpat
2
940
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
39k
非機能品質を作り込むための実践アーキテクチャ
knih
6
1.7k
DevFest 2024 Incheon / Songdo - Compose UI 조합 심화
wisemuji
0
220
事業貢献を考えるための技術改善の目標設計と改善実績 / Targeted design of technical improvements to consider business contribution and improvement performance
oomatomo
0
180
OCI技術資料 : ファイル・ストレージ 概要
ocise
3
11k
Featured
See All Featured
It's Worth the Effort
3n
183
28k
4 Signs Your Business is Dying
shpigford
182
21k
Optimizing for Happiness
mojombo
376
70k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.7k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
Visualization
eitanlees
146
15k
jQuery: Nuts, Bolts and Bling
dougneiner
62
7.6k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.4k
Building Applications with DynamoDB
mza
92
6.1k
Writing Fast Ruby
sferik
628
61k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Transcript
RamdaͰखܰʹ ؔܕݴޠΛ࢝ΊΑ͏ ɹ༎հ 2016/05/14 ॳՆͷJavaScriptࡇ
ࣗݾհ ༎հ ϓϩάϥϚʔ ؔܕݴޠΛษڧத ࠓظͷՇϠϞτ͞Μ ͍;Γͩͱ؋ਪ͠ twitter @pegass85 facebook yuusuke.takeuchi.96
ૣͰ͕͢Έͳ͞Μ javascriptͷϧʔϓॲཧʹ ࠔ͍ͬͯ·ͤΜ͔
ͦͷɺؔܕݴޠͷߟ͑ํΛ ͍ͬͯΕղܾͰ͖Δ͔
ࠓͷΞδΣϯμ खଓ͖ܕ -> ؔܕ ؔܕݴޠͷجຊతͳߟ͑ํ ࣮ྫ υΩϡϝϯτྨͳͲ
ࠓͷΞδΣϯμ खଓ͖ܕ -> ؔܕ ؔܕݴޠͷجຊతͳߟ͑ํ ࣮ྫ υΩϡϝϯτྨͳͲ
͜ͷॲཧΛͲ͏ॻ͖·͔͢ʁ TODOϦετ͕͋ͬͨͱ͠·͢ ϦετͰมߋ͕͋ͬͨͷ͚ͩΛऔΓग़͢ ˢͷσʔλΛAPIʹ͛ΔͨΊʹมߋ͢Δ
forΛͬͨΓํ let postData = []; for (let i in todo)
{ if(todo[i].isChanged) { postData.push(convertData(todo[i])); } }
Ͳ͕͜ͳͷ͔ʁ ωετ͕ਂͯ͘ෳࡶ ॲཧΛશ෦ݟͳ͍ͱpostData͕Ͳ͏ͳ͔ ͔Βͳ͍ ͜Ε͕30ߦ͘Β͍ʹͳͬͯɺωετ͕3ஈʹͳ Δͱखʹෛ͑ͳ͍ɾɾɾɾɾɾ
ͦ͜ͰRamdaͷग़൪ʂʂ
RamdaΛͬͯಉ͡ॲཧΛॻ͘ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,
chanegedList); ωετ͕ਂ͘ͳͯ͘γϯϓϧʹ ͔͠ɺมͷೖ͔ͯ͠Β มΘͬͯͳ͍
ࠓͷΞδΣϯμ खଓ͖ܕ -> ؔܕ ؔܕݴޠͷجຊతͳ໋ྩ ࣮ྫ υΩϡϝϯτྨͳͲ
ؔܕݴޠͷେݪଇ ྻͷશཁૉʹ ಉ͡ॲཧΛ͢Δ
جຊͦͷ̍ શཁૉΛม͢Δ MAP
جຊͦͷ2 ݅ʹ߹͏ཁૉ͚ͩ͢ FILTER
͖ͬ͞ͷ՝ΛؔܕͰߟ͑Δͱ FILTER มߋͨ͠Ϩίʔυ͚ͩ͢ MAP ͬͨͷΛ API༻ʹσʔλม ɾɾɾͱͳΔ
ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,
chanegedList); filter มߋͨ͠ίʔυ͚ͩ͢
ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,
chanegedList); ݅͢ɺؔͱͯ͠ఆٛ͢Δ
ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,
chanegedList); ͜͏͍͏ͷΛؔܕݴޠͰϥϜμࣜͱ͍͏
ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,
chanegedList); ؔͷϑΥʔϚοτҎԼͷ௨Γ ୈҰҾɿɹྻཁૉͷ Γɹɿɹboolean(trueͰ͢)
ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,
chanegedList); ͜ͷྫͰisChanged͕trueͳΒ มߋ͞Εͨͱݟͳ͍ͯ͠Δ ɹˣ มߋ͞Εͨཁૉ͚ͩΛ͢ͱ͍͏ҙຯʹͳΔ
ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,
chanegedList); ͜͜ʹFILTERରͷྻΛࢦఆ͢Δ
ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,
chanegedList); MAP API༻ʹσʔλม
ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,
chanegedList); ͜͜ʹσʔλม͢ΔؔΛࢦఆ͢Δ
ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,
chanegedList); ؔͷϑΥʔϚοτҎԼͷ௨Γ ୈҰҾɿɹྻཁૉͷ Γɹɿɹมޙͷσʔλ
ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,
chanegedList); ͜ͷྫͰconvertDataͰ σʔλม͢ΔͷͰɺ ͜ΕΛͦͷ··ࢦఆ͢Δ
ίʔυͱͷରԠ let chanegedList = R.filter(data=>data.isChanged, todo); let postData = R.map(convertData,
chanegedList); ͜͜ʹMAPରͷྻΛࢦఆ͢Δ
͜Μͳײ͡Ͱ MAPɺFILTERͳͲͷૢ࡞Λ Έ߹ΘͤͯॲஔΛॻ͍͍ͯ͘ ωετΛਂ͘͢Δ ͱ͍͏ߟ͕͑ͳ͍
ࠓͷΞδΣϯμ खଓ͖ܕ -> ؔܕ ؔܕݴޠͷجຊతͳ໋ྩ ࣮ྫ υΩϡϝϯτྨͳͲ
͜ͷॲཧΛؔܕͰॻ͍ͯΈΑ͏ TODOϦετ͕͋Γ·ͨ͠ 1Ϩίʔυ୯ҐͰΤϥʔνΣοΫAPIΛݺͿ Τϥʔ͚ͩநग़ͯ͠ɺΤϥʔσʔλʹมԽ͢Δ
·ͣPromise.allͰ·ͱΊͯ ΤϥʔνΣοΫ·Ͱࢥ͍ͭ͘ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { }); ˞isErrorPromiseΛฦ͠·͢
·ͣPromise.allͰ·ͱΊͯ ΤϥʔνΣοΫ·Ͱࢥ͍ͭ͘ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { }); TODOͷ֤Ϩίʔυ͝ͱʹ ΤϥʔνΣοΫAPIΛ࣮ߦ ˞isErrorPromiseΛฦ͠·͢
·ͣPromise.allͰ·ͱΊͯ ΤϥʔνΣοΫ·Ͱࢥ͍ͭ͘ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { }); TODOϦετΛΤϥʔνΣοΫ APIͷPromiseϦετʹมߋ ˞isErrorPromiseΛฦ͠·͢
˞isErrorPromiseΛฦ͠·͢ ·ͣPromise.allͰ·ͱΊͯ ΤϥʔνΣοΫ·Ͱࢥ͍ͭ͘ let promiseList = R.map(todo => isError(todo), todos);
Promise.all(promiseList).then(resps => { }); ͍ͭ͜ΛPromise.allʹ ͛ͯฒྻ࣮ߦ͢Δ
ͰɺTODOຊମͱΤϥʔνΣοΫ͕ผʑͷྻ ͔ͩΒɺॲཧ͕ࡶʹͳΓͦ͏ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { }); TODOຊମ ΤϥʔνΣοΫ݁Ռ
͜͜Ͱ৽͍͠ثΛհ 2ͭͷྻΛ߹ମͤ͞Δ ZIP
ZIPͷಈ࡞ྫ R.zip([1,2,3], ['a','b','c']) => [[1,'a'], [2, 'b'], [3, 'c']]
ZIPͰTODOϦετͱ ΤϥʔνΣοΫͷ݁ՌΛ߹ମͤ͞Δ TODO1 TODO1ͷΤϥʔνΣοΫ݁Ռ TODO2 TODO2ͷΤϥʔνΣοΫ݁Ռ ͜͜·Ͱ͘Εޙ؆୯ʂʂ ɾɾɾ
Promise.allͰ શϨίʔυͷΤϥʔAPIΛݺͿ zip todoϦετͱPromiseͷϨεϙϯεΛ߹ମ filter ΤϥʔͷͷΛ͢ map Τϥʔσʔλʹม͢Δ
ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); });
ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); R.pipeͰෳͷॲཧΛܨ͔͚͛ͯ·͢
ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); ͜͜ʹ࠷ॳͷॲཧʹ͢ҾΛࢦఆ
ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); ࠓճTODOຊମͱ ΤϥʔνΣοΫ݁Ռ
ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); TODOຊମͱΤϥʔνΣοΫ݁ՌΛ߹ମ
ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); R.zipͷ݁Ռ͕͍ͭ͜ͷॲཧରʹͳΔ
ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); item[0] : todoຊମ item[1] : ΤϥʔνΣοΫ݁Ռ
ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); ͜ͷ݅Τϥʔ͕͋Δ Ϩίʔυ͚ͩΛ͢ͱ͍͏ҙຯ
ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); ͬͺΓR.filterͷ݁Ռ͕ೖྗʹͳΔ
ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); ͜͜ͰΤϥʔσʔλʹม͢Δ
ίʔυͰॻ͘ͱ͜͏ͳΓ·͢ let promiseList = R.map(todo => isError(todo), todos); Promise.all(promiseList).then(resps
=> { let errorData = R.pipe( R.zip, R.filter(item => item[1].isError), R.map(item => getErrorData(item[0].id)) )(todos, resps); }); Τϥʔσʔλͷྻ͕֨ೲ͞ΕΔ
ෳࡶͦ͏ͳॲཧͰ ׂͱγϯϓϧʹ͔͚·ͨ͠ ͜ͷΑ͏ʹ
ࠓͷΞδΣϯμ खଓ͖ܕ -> ؔܕ ؔܕݴޠͷجຊతͳ໋ྩ ࣮ྫ υΩϡϝϯτྨͳͲ
ެࣜαΠτ ϓϩδΣΫτϖʔδ http:/ /ramdajs.com/0.21.0/index.html υΩϡϝϯτ http:/ /ramdajs.com/0.21.0/docs/ Try Ramda (ϒϥβͰRamda͕ࢼͤ·͢)
http:/ /ramdajs.com/repl/?v=0.21.0
ίʔυͷαϯϓϧ ࠷ॳʹղઆͨ͠FILTERɺMAPΛ͏ͷ http:/ /goo.gl/AC4bfS ࠷ޙʹղઆͨ͠ZIPΛ͏ͭ http:/ /goo.gl/eoI0u9 TRY RamdaͰॻ͖·ͨ͠ ͙͢ʹಈ͖·͢ʂʂ
͝ਗ਼ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠