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
Obtaining Closure with Anonymous Functions
Search
Andrew Cassell
May 22, 2014
Programming
0
530
Obtaining Closure with Anonymous Functions
PHP Functional Programming using Functions, Lambdas, Anonymous Functions, and Closures.
Andrew Cassell
May 22, 2014
Tweet
Share
More Decks by Andrew Cassell
See All by Andrew Cassell
Immutability to Save an Ever-Changing World
cassell
0
40
Immutability to Save an Ever-Changing World
cassell
0
17
Domain-driven Design Workshop
cassell
1
260
Immutability to save an ever-changing world
cassell
3
480
Introduction to Domain-Driven Design in PHP - ZendCon & OpenEnterprise 2018
cassell
3
720
Immutability to Save an Ever-Changing World - PHP Benelux 2018
cassell
1
630
Domain-driven Design in PHP - PHP Benelux 2018
cassell
1
160
php[world] 2017 Domain-Driven Design Workshop
cassell
1
290
Domain-Driven Design
cassell
2
890
Other Decks in Programming
See All in Programming
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
220
Unity Android XR入門
sakutama_11
0
160
Ruby on cygwin 2025-02
fd0
0
140
Linux && Docker 研修/Linux && Docker training
forrep
24
4.5k
Pythonでもちょっとリッチな見た目のアプリを設計してみる
ueponx
1
550
定理証明プラットフォーム lapisla.net
abap34
1
1.8k
Djangoアプリケーション 運用のリアル 〜問題発生から可視化、最適化への道〜 #pyconshizu
kashewnuts
1
250
プログラミング言語学習のススメ / why-do-i-learn-programming-language
yashi8484
0
130
AWSマネコンに複数のアカウントで入れるようになりました
yuhta28
2
160
Amazon Bedrock Multi Agentsを試してきた
tm2
1
280
富山発の個人開発サービスで日本中の学校の業務を改善した話
krpk1900
4
380
『GO』アプリ バックエンドサーバのコスト削減
mot_techtalk
0
140
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.6k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
630
Navigating Team Friction
lara
183
15k
Code Reviewing Like a Champion
maltzj
521
39k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
How to Think Like a Performance Engineer
csswizardry
22
1.3k
Become a Pro
speakerdeck
PRO
26
5.1k
For a Future-Friendly Web
brad_frost
176
9.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
34
2.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Transcript
Obtaining Closure with Anonymous Functions @alc277
Functions&! Lambdas&! Anonymous&! Closures&! Fun.
Named Functions
Named Functions
Functions&! Lambdas&! Anonymous&! Closures&! Fun.
NAMED LAMBDA
Lambda Functions
None
Lambda Functions
Lambda Functions
Type Hinting
Wow much useful such amaze ! very programmer
Functions&! Lambdas&! Anonymous&! Closures&! Fun.
None
Anonymous Functions
Functions&! Lambdas&! Anonymous&! Closures&! Fun.
λ Closures Rasmus’s Throne Room
None
Lambda Variable Scope
Closure Variable Scope & “use”
Tricky Bit
Passing a Variable to a Lambda or Closure
None
Passing a Variable by Reference to a Lambda or Closure
None
None
Closure Class
Closure! {! ! /* Methods */! ! public bindTo ()
{ }! ! ! ! ! ! ! ! } PHP Closure Class ! ! ! ! public static bind () {}! ! ! ** double-secret function __invoke() { }! !
None
Reasons to use Closures • Variable Scope and Binding! •
Don’t Pollute Namespace With Functions! • Map/Reduce/Filter! • Data Output! • Retrieving Records from Database
• Currying! • Fixed-point Combinators (Y- Combinator)! • Improved Performance
(Memoization)! • Monads! • Dependency Injection Reasons to use Closures
Things to Avoid • create_function! • Closure::bind()
Map/Reduce/Filter
Map/Reduce/Filter with Lambda Credit: Fabien Potencier
Map/Reduce/Filter Credit: Fabien Potencier Map/Reduce/Filter with Closure
Currying Photo: Penn State Office of Research Communications.
Currying
DATA OUTPUT
Data Output
Data Output
Database Records
Data Output
Y-Combinator
Y-Combinator
Y-Combinator
None
Memoization
fib(5) = fib(3) + fib(4)! fib(3) = fib(1) + fib(2)!
fib(1) = 1! fib(2) = fib(1) + fib(0)! fib(1) = 1! fib(0) = 0! fib(2) = 1 + 0 = 1! fib(3) = 1 + 1 = 2! fib(4) = fib(3) + fib(2)! fib(3) = fib(1) + fib(2)! fib(1) = 1! fib(2) = fib(1) + fib(0)! fib(1) = 1! fib(0) = 0! fib(2) = 1 + 0 = 1! fib(3) = 1 + 1 = 2! fib(2) = fib(1) + fib(0)! fib(1) = 1! fib(0) = 0! fib(2) = 1 + 0 = 1! fib(4) = 2 + 1 = 3! fib(5) = 3 + 2 = 5
Memoization
1 1 2 1 3 2 4 3 5 5
6 8 7 13 8 21 9 34 10 55 11 89 12 144 13 233 14 377 15 610 16 987
Memoization
None
Monads
MonadPHP Anthony Ferrara
Monads Credit: Anthony Ferrara
Monads Credit: Anthony Ferrara
Monads Credit: Anthony Ferrara
$posts = [! [“title" => "foo", "author" => [“name" =>
"Bob", "email" => “
[email protected]
”]],! [“title" => "bar", "author" => array("name" => "Tom", "email" => “
[email protected]
”]],! [“title" => “baz"],! [“title" => "biz", "author" => array("name" => "Mark", "email" => “
[email protected]
”]],! ]; Monads Credit: Anthony Ferrara
Monads Credit: Anthony Ferrara
Dependency! Injection
Dependency Injection
Dependency Injection
Dependency Injection
Dependency Injection
Dependency Injection