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 Patterns
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Robin Palotai
September 18, 2012
Programming
490
7
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Functional Programming Patterns
A short enumeration of selected patters occuring in FP.
Robin Palotai
September 18, 2012
More Decks by Robin Palotai
See All by Robin Palotai
A subjective on Functional Programming
ron
4
360
SwfControl
ron
0
67
Other Decks in Programming
See All in Programming
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
4k
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
170
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
2
640
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
750
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
170
Claspは野良GASの夢をみるか
takter00
0
190
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.6k
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
230
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
540
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.7k
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
330
Featured
See All Featured
Done Done
chrislema
186
16k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
780
The Limits of Empathy - UXLibs8
cassininazir
1
360
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
We Are The Robots
honzajavorek
0
250
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Documentation Writing (for coders)
carmenintech
77
5.4k
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
290
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.1k
Building Adaptive Systems
keathley
44
3.1k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.9k
Transcript
Functional Programming Patterns
1st class functions Functions are values too. They have type.
Can be assigned to variables. f: a b → g: (a, b) c → input type output type → multiple arguments
Higher order funs A higher order function is a function
that takes other functions as argument. h: ([a], a b) [b] → → list elem mapper Strategy pattern-like
Currying f: (a, b) c → f: a b c
→ → f: a (b c) → → curried form right-associative Factory pattern-like
Pure Functions Referential transparency – expression replaceable with its value
without changing program semantics. easy to reason about optimizable
Immutability Values are constructed and then never modified. persistent collections
tuples and Lists pair: (a, b) 3-tuple: (a, b, c)
1 :: 2 :: 3 :: Nil [1, [2, [3, []]]] heterogeneous fixed lengthc homogeneous unbounded length
Transform Recursion is low-level flow control. Usages can be abstracted.
Tell what, not how. map, filter, fold
Algebraic Data Types data List a = Cons a (List
a) | Nil data Tree a = Node (Tree a) a (Tree a) | Empty
Functor A functor is a computational context. Map applies a
normal function to a value in a context. map: f a (a b) f b → → → F<A> (A B) F<B> → → → fmap
Monad point: a f a → flatMap: f a (a
f b) f → → → b A context with richer operations. pure, return bind
Option Nulls made explicit. No more NPE. data Option a
= Some a | None orElse: Opt a Opt a Opt a → → getOrElse: Opt a a a → → Monad
Either data Either a b = Left a | Right
b Often used for error handling, where error is on the left, success on the right. Monad for a fixed a
Future Promise / Future is a context, where the contained
computation may execute concurrently. Used to compose async computations without blocking. Monad
Typeclasses A typeclass describes a contract. A typeclass instance describes
how a given data type fulfills that contract. Like an Adapter, but more versatile.
Semigroup Monoid , Semigroup defines addition. Monoid is semigroup with
an identity element. Pops all over your code!
Foldable A foldable provides means for stateful traversal. foldLeft: f
a b (b a b) b → → → → → Nice cooperation with Monoids
Extra stuff Applicative functors, Monad transformers, Relational databases, Linear logic,
IO, DI, Logging, Total FP, Actors, ...
Thx