Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
談談_Functional_Programming.pdf
Search
CypressKuo
August 30, 2019
Technology
33
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
談談_Functional_Programming.pdf
CypressKuo
August 30, 2019
More Decks by CypressKuo
See All by CypressKuo
Deep-copying.pdf
cypresskuo
0
42
CSS_for_Web_Vitals.pdf
cypresskuo
0
48
談談_Code_review.pdf
cypresskuo
0
56
REST_vs_GraphQL_今夜はご注文はどっち.pdf
cypresskuo
0
30
CSS_重構.pdf
cypresskuo
0
30
跟上_JS_的腳步-ES2020.pdf
cypresskuo
0
39
Core_Web_Vitals.pdf
cypresskuo
0
62
這個時代人人都知道的敏捷開發.pdf
cypresskuo
0
83
Webassembly.pdf
cypresskuo
0
21
Other Decks in Technology
See All in Technology
1週間、Opus封印でお願いします
kintotechdev
0
160
Filter What the LLM Reads: RAG Governance with AgentCore Gateway
yakumo
0
110
国際カードブランドルール変更に伴うクレジットカード決済取引仕様変更について
k1style
0
240
Microsoft のサポート ライフサイクルを理解する
murachiakira
PRO
0
210
ビジネス部門からPOを迎えての半年間の進歩と課題
zozotech
PRO
0
140
freeeにおける AI を用いた ブラウザ動作確認の自動化の取り組み
freee
PRO
0
220
シンプルな設定ファイルで実現する AWS IAM Identity Center の ユーザー管理Terraformフレームワークを公開しました / Simplifying AWS IAM Identity Center User Management: An Open-Source Terraform Framework
yamaguchitk333
0
320
freeeにおけるSoftware Factory
freee
PRO
0
520
クラウドエージェントの先駆け Devin。今も最先端を走る、他との違い
kinopeee
0
380
AWSDirectConnectの構築の進め方を整理してみた
masa_my
1
190
VLA-JEPA: Enhancing Vision-Language-Action Models with Latent World Models
takmin
0
330
Teaching Python with three kinds of AI
reuven
0
120
Featured
See All Featured
Faster Mobile Websites
deanohume
310
32k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Done Done
chrislema
187
17k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
ラッコキーワード サービス紹介資料
rakko
4
5.5M
What's in a price? How to price your products and services
michaelherold
247
13k
A designer walks into a library…
pauljervisheath
211
25k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
600
Transcript
談談 Functional Programming CypressKuo @前端組例會 2019/08/30
In computer science, functional programming is a programming paradigm. --wikipedia
None
None
None
None
Function 的特色 First-class High Order Function No side effect Referential
transparency Pure Function
First-class 函數與其他數據類型一樣,處於平等地位。 • 被賦值到其他變數 • 作為參數傳入到不同的函數中 • 作為函數的回傳值
None
High Order Function 滿足以下兩項其中之一的函數 • 將函式當成參數傳入的函式 • 將函式當成回傳值的函式
None
常見的 High Order Function Array.prototype.map(foo) Array.prototype.filter(foo) Array.prototype.reduce(foo) Array.prototype.forEach(foo) Array.prototype.some(foo) Array.prototype.every(foo)
No side effect 沒有與外部互動,產生與運算無關的其他結果。 anti pattern: • 發送 http request
• 印出 console • 取得使用者的 input
Referential transparency 不管外部環境如何,只要參數相同,函式執行的返回結果必定相同。
Pure Function 結合 no side effect 與 Referential transparency 一個
function 給予相同的參數, 永遠會回傳相同的返回值,並且沒有任何顯著的副作用。
None
None
Function Composition Curry Compose
Curry 將一個有 N 個參數的函數轉換成 N 個只有一個參數的函數
None
Compose 把兩個以上的一個參數函數合併起來串聯多個組合成新的函數
None
Functor 範疇間的一類映射 F(f . g) = F(f) . F(g) (
. 代表 compose) F 就是 Functor
None
抽象化 縮減一個概念或是一個現象的資訊含量來將其廣義化的過程
🍎 + 🍎 = 🍎🍎 🍌 + 🍌 = 🍌🍌
(🍎🍎) + (🍎🍎) + (🍎🍎) = 🍎🍎🍎🍎🍎🍎 (🍌🍌) + (🍌🍌) + (🍌🍌) = 🍌🍌🍌🍌🍌🍌 抽象化
1 + 1 = 2 進一步 => fn(1, 1) ->
2 // fn = (a, b) => a + b; 2 + 2 + 2 = 6 進一步 => 2 * 3 = 6 再進一步 => fn(2, 3) -> 6 // fn = (a, b) => a * b; 抽象化
資料與功能分離,不要直接操作資料 抽象化 in FP
None
None
實例
優勢: • 可讀性高 • 可維護性高 • 簡潔,開發快速 劣勢: • 難以入門
優劣
If all you have is a hammer, everything looks like
a nail. 活用工具,不是被工具所用。 結論
Q & A
• https://speakerdeck.com/s6323859/abstract-thinking-cong-functional-programming-k an-jian-cheng-shi-zhi-mei • https://docs.google.com/presentation/d/1ZvBmQlNoeTOxV5oArnOcES-iswSqPovTe Y4hyWz3N0c/edit?usp=sharing • http://www.ruanyifeng.com/blog/2017/03/pointfree.html 參考資料
wish you a nice day!