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
0
950
関数型でGoFのデザインパターンやってみる
こわくない関数型プログラミング勉強会@福岡 #2(2019/09/06)の発表資料です。
ponday
September 06, 2019
Tweet
Share
More Decks by ponday
See All by ponday
TypeScriptの型表現
honda
10
2.8k
Web Componentsの今
honda
1
370
これまでのReact、これからのReact
honda
0
240
Gatsbyお試し
honda
0
110
styled-components or emotion?
honda
0
600
Web ComponentsとAngular
honda
0
130
Atomic Design周りについての私見
honda
1
530
え、まだWeb Componentsを未来の技術だと思ってるの?
honda
2
680
Web Componentsの動向とPolymer
honda
4
2.2k
Other Decks in Programming
See All in Programming
Rails と人魚の話/rails-and-mermaid
sanfrecce_osaka
0
100
Code Reviews
bkuhlmann
4
880
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
3
750
From Spring Boot 2 to Spring Boot 3 with Java 22 and Jakarta EE
ivargrimstad
0
890
甘い香りに誘われてVanilla Extractを1年間運用してみた
miyahkun
1
110
PHPの次期バージョンはこの時期どうなっているのか - Internalsの開発体制について - PHPカンファレンス小田原
youkidearitai
PRO
1
180
Designing for tomorrow's programming workflows
honnibal
PRO
2
110
今の SmartHR にエンジニアで入社するとどうなるの?
daisukeshinoku
5
4.6k
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
8
3.6k
Ruby製社内ツールのGo移行
bgpat
2
330
デザインシステムで Tailwind CSSとCSS in JSに分散投資をしたら良かった話
fsubal
18
4.8k
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
440
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
59
5k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
20
1.6k
Creatively Recalculating Your Daily Design Routine
revolveconf
209
11k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
240
1.2M
A designer walks into a library…
pauljervisheath
199
23k
Documentation Writing (for coders)
carmenintech
59
3.9k
Build your cross-platform service in a week with App Engine
jlugia
225
17k
What's new in Ruby 2.0
geeforr
337
31k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Building Applications with DynamoDB
mza
88
5.6k
Fantastic passwords and where to find them - at NoRuKo
philnash
36
2.5k
Building an army of robots
kneath
300
41k
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/