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
ねことはじめる関数型 / functional programming with cats
Search
ぷに
February 29, 2020
Technology
1.3k
1
Share
ねことはじめる関数型 / functional programming with cats
VRC LT #7
ぷに
February 29, 2020
More Decks by ぷに
See All by ぷに
数値計算の呪いとあそぼぅ!!/ the curse of numerical calculus
punilfin
1
47
Other Decks in Technology
See All in Technology
Copilot CLI・IDE・Web・スマホで途切れない開発フローを目指して / One Copilot flow - CLI IDE Web Mobile
aeonpeople
1
970
Harnessing the Power of Mocks and Stubs in PHPUnit / #laravellivejp
asumikam
0
160
【禁断】Obsidianの第二の脳に「知の巨人」と呼ばれた師匠の脳をロードしてみた
nagatsu
0
6.3k
TypeScriptエンジニアのためのWASMランタイム入門:AssemblyScriptから理解するメモリの実態(ayano)
ayanoyuki
0
130
Kaggle未経験社員をメダリストに育てる「AIドラゴン桜」
lycorptech_jp
PRO
0
530
layerx-fde-practices
cipepser
6
2.7k
データ分析基盤の信頼を支える視点と設計
yuki_saito
1
630
AIのために、AIを使った、Effect-TSからの脱却 〜テストを活用した安全なリファクタリングの進め方〜
bitkey
PRO
1
540
AIコーディングエージェントの活用で、コードは静かに肥大化した
yosukeshinoda
1
340
データ基盤構築・運用の現場から 〜 Snowflake Intelligence 導入で変わった、データ活用の未来 〜
wonohe
0
170
シンデレラなんかになりたくない!ガラスの靴が割れた時代にどう歩く?
nomizone
0
190
long-running-tasks
cipepser
2
260
Featured
See All Featured
First, design no harm
axbom
PRO
2
1.2k
Technical Leadership for Architectural Decision Making
baasie
3
370
YesSQL, Process and Tooling at Scale
rocio
174
15k
Typedesign – Prime Four
hannesfritz
42
3k
Being A Developer After 40
akosma
91
590k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
170
The World Runs on Bad Software
bkeepers
PRO
72
12k
Design in an AI World
tapps
1
210
From π to Pie charts
rasagy
0
190
The SEO identity crisis: Don't let AI make you average
varn
0
470
Fireside Chat
paigeccino
42
3.9k
Transcript
Ͷ͜ͱ͡ΊΔؔܕ ʹ (ehlfin_puni / punilfin) 2020/03/27
͜͡͠ΐ͏͔͍ ͳ·͑ɿʹ VRC ID : ehlfin_puni Twitter : punilfin 2020/02/10
ʹ VRC ʹ͖·ͨ͠ ͠ΐ͠Μ͠ΌͰ͢ɽͯ͘͞͠͠Ͷ ͖͢ɿ͢͏͕͘ ͖͚ͩ͢ͲͳʹΘ͔Βͳ͍Ͱ͢ɽͯ͘͞͠͠Ͷ ͖͢͡Όͳ͍ɿΖ͙ΒΈΜ͙ ͱ ͖͔͍͕͘͠Ύ͏ ͱ͘ʹ͖Β͍ɿ JavaScript
͍·͔Β Scala with Cats ͱ͍͏ຊͷΛ͠·͢ Cats Λμγʹͯؔ͠ܕͷߟ͑ํΛֶͿຊ Cats ʜ Scala
ͰΰϦΰϦؔܕ͢ΔͷΛิॿ͢ΔϥΠϒϥϦ Cats ͷ͍ํΛֶͿຊ
͜͜ʹ͋Γ·͢ Figure: https://underscore.io/books/scala-with-cats/
ಡΜͩܦҢ ͓͠͝ͱͰ Scala ͷϨϏϡʔΛ͠ͳ͍ͱ͍͚ͳ͍ Scala Βͳ͍ʂ ݍษڧ͚ͯͨ͠Ͳ Monad ͕ग़ͯ͘Δલʹ͖ͯΊͨ Monad
Βͳ͍ʂ ྆ํ·ͱΊͯษڧͰ͖ͳ͍͔ͳʁ
ຊͷষཱͯ Monoids and Semigroups Functors Monads Monad Transformers Semigroupal and
Applicative Foldable and Traverse Testing Asynchronous Code Map-Reduce Data Validation CRDTs ײ ාͦ͏
ಡΜͰΈͨײ ͋·Γා͘ͳ͍ Option, Future, List ͳͲɼScala ͰΑ͘͏֓೦ΛΑ͘ݟ͢ͱ͜Ζ͔Βελʔτ ͦΕΒͷڞ௨ੑ࣭ΛऔΓग़͢͜ͱͰ Monad ͳͲͷந֓೦ঃʑʹ
࠷ۙ͋ͬͨ͜ͱ Javascript ͷ࣭Λ͞Εͨ Γ͍ͨ͜ͱɿ ʮ2 ͭͷ Promise ͷ݁Ռ͕ग़ଗ͔ͬͯΒɺ2 ͭͷ݁ՌΛՃͯ͠ฦ͢ʯ ฉ͍ͨॠؒʹʮݴޠͷ
built-in ͚ؔͩͰͰ͖ͦ͏ͩʯͱࢥͬͨ ௐͨΒ Promise.all() ͕ώοτͨ͠
ਪաఔ ܕΫϥε F ʹରͯ͠ F[A] ͱ F[B] ͔Β F[A,B] ܕΛ࡞Γ͍ͨ
F ͕ Cartesian ͳΒ product ͰͰ͖Δ ͳͷͰ Promise ͕ Cartesian Ͱ͋Δ͜ͱΛࣔͤ OK Promise Scala Ͱ͍͏ͱ͜Ζͷ Future ͔ͩΒ Monad Ұൠʹ Monad ) Applicative ) Cartesian ͳͷͰ OK ೦ͳ͓Βͤ ͜ͷਪେ͖ͳ͕݀͋Δ Javascript ͷ Promise Monad Ͱͳ͍ Functor Ͱ͢Βͳ͍ Cartesian ʹݟ͑Δͷଟۮવ
ݸਓతʹࢥ͍ͬͯΔ͜ͱ ؔܕͷߟ͑ํ͕ʮৗʹਖ਼͍͠ʯΘ͚ͳ͍ ͕ɼ ʮؔܕҎ֎ؔܕͷߟ͑ํ͕͑ͳ͍ʯͷ͔ʁ Ͳ͜·Ͱʢແཧͳ͘ʣ௨༻͢Δ͔ߟ͍͑ͨ ʢཧʣֶ͔Βٕज़ാʹೖͬͨࢲʹͱͬͯɼ ʮֶͬΆ͍ߟ͑ํ͕͑Δ͜ͱʯཧղΛ͛ Δ্Ͱେ͖ͳॿ͚ʹͳΔ
·ͱΊ Figure: Cats ͷΛ͠·ͨ͠ɽࣸਅ࣮ՈͷͶ͜Ͱ͢ɽ