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
談談_Functional_Programming.pdf
Search
CypressKuo
August 30, 2019
Technology
0
29
談談_Functional_Programming.pdf
CypressKuo
August 30, 2019
Tweet
Share
More Decks by CypressKuo
See All by CypressKuo
Deep-copying.pdf
cypresskuo
0
33
CSS_for_Web_Vitals.pdf
cypresskuo
0
39
談談_Code_review.pdf
cypresskuo
0
45
REST_vs_GraphQL_今夜はご注文はどっち.pdf
cypresskuo
0
23
CSS_重構.pdf
cypresskuo
0
27
跟上_JS_的腳步-ES2020.pdf
cypresskuo
0
29
Core_Web_Vitals.pdf
cypresskuo
0
54
這個時代人人都知道的敏捷開發.pdf
cypresskuo
0
59
Webassembly.pdf
cypresskuo
0
13
Other Decks in Technology
See All in Technology
わたしがセキュアにAWSを使えるわけないじゃん、ムリムリ!(※ムリじゃなかった!?)
cmusudakeisuke
1
670
Go標準パッケージのI/O処理をながめる
matumoto
0
160
AI は "道具" から "同僚" へ 自律型 AI エージェントの最前線と、AI 時代の人材の在り方 / Colleague in the AI Era - Autonomous AI Seminar 2026 at Niigata
gawa
0
160
マルチロールEMが実践する「組織のレジリエンス」を高めるための組織構造と人材配置戦略
coconala_engineer
3
720
開発組織の課題解決を加速するための権限委譲 -する側、される側としての向き合い方-
daitasu
5
610
IBM Bobを使って、PostgreSQLのToDoアプリをDb2へ変換してみよう/202603_Dojo_Bob
mayumihirano
1
320
作りっぱなしで終わらせない! 価値を出し続ける AI エージェントのための「信頼性」設計 / Designing Reliability for AI Agents that Deliver Continuous Value
aoto
PRO
2
280
堅牢.py#2 LT資料
t3tra
0
140
Claude Codeが爆速進化してプラグイン追従がつらいので半自動化した話 ver.2
rfdnxbro
0
520
銀行の内製開発にて2つのプロダクトを1つのチームでスクラムしてみてる話
koba1210
1
110
Claude Codeの進化と各機能の活かし方
oikon48
22
12k
AIエージェント、 社内展開の前に知っておきたいこと
oracle4engineer
PRO
2
110
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
260
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
エンジニアに許された特別な時間の終わり
watany
106
240k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
140
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
410
Into the Great Unknown - MozCon
thekraken
40
2.3k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
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!