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
AWSだけでネット対戦できるブラウザゲームを作った話
kaidouji85
0
30
GitHub CopilotでJavaScript開発効率を爆上げする
kaidouji85
0
55
Serverless + Fargate構成で継続的デリバリーの速度を劇的に改善した話
kaidouji85
0
710
サーバーレスアーキテクチャこそ"ヘキサゴナルアーキテクチャ"
kaidouji85
0
51
サーバーレスでターンベース制のネット対戦ゲームを作った話
kaidouji85
0
480
CDKで構築したFargateのデプロイ時間を改善した話
kaidouji85
2
430
ブラウザゲームで視聴者参加型のゲーム配信
kaidouji85
0
240
JSだけでバックエンド環境構築、IaC、自動デプロイまでやってみた話
kaidouji85
0
310
サーバレスでネット対戦を作った話
kaidouji85
0
510
Other Decks in Technology
See All in Technology
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
3
390
SREが投資するAIOps ~ペアーズにおけるLLM for Developerへの取り組み~
takumiogawa
1
340
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
310
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
組織成長を加速させるオンボーディングの取り組み
sudoakiy
2
170
Can We Measure Developer Productivity?
ewolff
1
150
OTelCol_TailSampling_and_SpanMetrics
gumamon
1
170
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
120
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
230
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
590
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
130
SRE×AIOpsを始めよう!GuardDutyによるお手軽脅威検出
amixedcolor
0
130
Featured
See All Featured
Producing Creativity
orderedlist
PRO
341
39k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Automating Front-end Workflow
addyosmani
1366
200k
Rails Girls Zürich Keynote
gr2m
94
13k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
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Ͱॻ͖·ͨ͠ ͙͢ʹಈ͖·͢ʂʂ
͝ਗ਼ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠