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
関数型でGoFのデザインパターンやってみる
Search
ponday
September 06, 2019
Programming
1
1.6k
関数型でGoFのデザインパターンやってみる
こわくない関数型プログラミング勉強会@福岡 #2(2019/09/06)の発表資料です。
ponday
September 06, 2019
Tweet
Share
More Decks by ponday
See All by ponday
TypeScriptの型表現
honda
10
3.1k
Web Componentsの今
honda
1
460
これまでのReact、これからのReact
honda
0
320
Gatsbyお試し
honda
0
130
styled-components or emotion?
honda
0
700
Web ComponentsとAngular
honda
0
140
Atomic Design周りについての私見
honda
1
770
え、まだWeb Componentsを未来の技術だと思ってるの?
honda
2
870
Web Componentsの動向とPolymer
honda
4
2.7k
Other Decks in Programming
See All in Programming
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
400
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
230
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
390
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
290
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
160
Oxlintはいいぞ
yug1224
5
1.3k
2026年 エンジニアリング自己学習法
yumechi
0
130
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
120
余白を設計しフロントエンド開発を 加速させる
tsukuha
7
2.1k
Grafana:建立系統全知視角的捷徑
blueswen
0
320
AIエージェントの設計で注意するべきポイント6選
har1101
7
3.4k
Featured
See All Featured
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
180
Exploring anti-patterns in Rails
aemeredith
2
240
Everyday Curiosity
cassininazir
0
130
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
62
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
61
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
720
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
150
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
So, you think you're a good person
axbom
PRO
2
1.9k
Transcript
関数型でデザインパターンやってみる こわくない関数型プログラミング勉強会@福岡 #2 / Sep 5th, 2019 ponday (@ponday_dev)
Profile - ponday (Honda, Yusuke) - フロントエンド好き - 副業もやってます
前回のイベントにて
GoFのデザインパターンを関数型で書いたら どうなりますか?
やってみる
GoFのデザインパターン - Abstract Factory - Adapter - Bridge - Builder
- Chain of Responsibility - Command - Composite - Decorator - Facade - Factory Method - Flyweight - Interceptor - Iterator - Mediator - Memento - Observer - Prototype - Proxy - Singleton - State - Strategy - Template Method - Visitor
State / Strategy - 持つべき振る舞いをinterfaceに定義 - interfaceを実装して実際の振る舞いを作成 - インスタンスを差し替えて動作を切り替え
例:Stateパターン
例:Stateパターン
Builder - インスタンスの操作を担うBuilderをinterfaceとして定義 - Builderを実装して具体的な方法を定義 - DirectorはBuilderを使ったインスタンスの構築方法を定義
例:Builderパターン
例:Builderパターン
似たような処理は書けるけど......
そもそもGoFのデザパタは OOP向け (不要なものも...)
関数型プログラミングでは、 高階関数 と 部分適用 を多用する
高階関数 - 関数を引数、戻り値で使う関数のこと - map / filter / reduce など
- 処理の移譲などに使う
部分適用 - 関数の引数の一部をあらかじめ固定する処理
例:高階関数と部分適用
例:高階関数と部分適用 高階関数
例:高階関数と部分適用 部分適用
例:高階関数と部分適用
例:高階関数と部分適用(パターン2)
例:高階関数と部分適用(パターン2)
まとめ - GoFはOOPについてのデザインパターン - 関数型プログラミングでも有効というわけではない - 実現できない or 余計なものもある
- 関数型プログラミングでは高階関数と部分適用を多用する - 処理の分岐や移譲は高階関数で実現
さいごにちょっと 宣伝
9/22の技術書典7で関数型プログラミングの本出します ↓他新刊(自社有志による執筆)
https://frontend-conf.fukuoka.jp/