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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
ponday
September 06, 2019
Programming
1.6k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
関数型でGoFのデザインパターンやってみる
こわくない関数型プログラミング勉強会@福岡 #2(2019/09/06)の発表資料です。
ponday
September 06, 2019
More Decks by ponday
See All by ponday
TypeScriptの型表現
honda
10
3.1k
Web Componentsの今
honda
1
480
これまでのReact、これからのReact
honda
0
340
Gatsbyお試し
honda
0
140
styled-components or emotion?
honda
0
730
Web ComponentsとAngular
honda
0
160
Atomic Design周りについての私見
honda
1
800
え、まだWeb Componentsを未来の技術だと思ってるの?
honda
2
880
Web Componentsの動向とPolymer
honda
4
2.8k
Other Decks in Programming
See All in Programming
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.4k
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
140
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
210
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.5k
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
220
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
610
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.5k
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
200
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
250
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
610
Creating Composable Callables in Contemporary C++
rollbear
0
170
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
310
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
sira's awesome portfolio website redesign presentation
elsirapls
0
290
Leo the Paperboy
mayatellez
7
1.9k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Claude Code のすすめ
schroneko
67
230k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.7k
Making the Leap to Tech Lead
cromwellryan
135
9.9k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
Navigating Team Friction
lara
192
16k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
620
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/