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.4k
関数型で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
440
これまでのReact、これからのReact
honda
0
320
Gatsbyお試し
honda
0
120
styled-components or emotion?
honda
0
700
Web ComponentsとAngular
honda
0
140
Atomic Design周りについての私見
honda
1
730
え、まだWeb Componentsを未来の技術だと思ってるの?
honda
2
850
Web Componentsの動向とPolymer
honda
4
2.6k
Other Decks in Programming
See All in Programming
AIを駆使して新しい技術を効率的に理解する方法
nogu66
1
660
Micro Frontendsで築いた 共通基盤と運用の試行錯誤 / Building a Shared Platform with Micro Frontends: Operational Learnings
kyntk
0
1.6k
イベントストーミングのはじめかた / Getting Started with Event Storming
nrslib
1
750
Developing Specifications - Jakarta EE: a Real World Example
ivargrimstad
0
240
なあ兄弟、 余白の意味を考えてから UI実装してくれ!
ktcryomm
5
2.1k
仕様がそのままテストになる!Javaで始める振る舞い駆動開発
ohmori_yusuke
8
4.7k
TypeScriptで設計する 堅牢さとUXを両立した非同期ワークフローの実現
moeka__c
5
2.5k
Stay Hacker 〜九州で生まれ、Perlに出会い、コミュニティで育つ〜
pyama86
2
2.7k
レイトレZ世代に捧ぐ、今からレイトレを始めるための小径
ichi_raven
0
470
これだけで丸わかり!LangChain v1.0 アップデートまとめ
os1ma
4
140
[堅牢.py #1] テストを書かない研究者に送る、最初にテストを書く実験コード入門 / Let's start your ML project by writing tests
shunk031
11
6.1k
Querying Design System デザインシステムの意思決定を支える構造検索
ikumatadokoro
1
1.2k
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
Bash Introduction
62gerente
615
210k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3k
How STYLIGHT went responsive
nonsquared
100
5.9k
Git: the NoSQL Database
bkeepers
PRO
432
66k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
54k
Why You Should Never Use an ORM
jnunemaker
PRO
60
9.6k
Context Engineering - Making Every Token Count
addyosmani
9
420
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/