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
Obtaining Closure with Anonymous Functions
Search
Andrew Cassell
May 22, 2014
Programming
580
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Obtaining Closure with Anonymous Functions
PHP Functional Programming using Functions, Lambdas, Anonymous Functions, and Closures.
Andrew Cassell
May 22, 2014
More Decks by Andrew Cassell
See All by Andrew Cassell
Immutability to Save an Ever-Changing World
cassell
0
85
Immutability to Save an Ever-Changing World
cassell
0
82
Domain-driven Design Workshop
cassell
1
310
Immutability to save an ever-changing world
cassell
3
600
Introduction to Domain-Driven Design in PHP - ZendCon & OpenEnterprise 2018
cassell
3
850
Immutability to Save an Ever-Changing World - PHP Benelux 2018
cassell
1
1.1k
Domain-driven Design in PHP - PHP Benelux 2018
cassell
1
230
php[world] 2017 Domain-Driven Design Workshop
cassell
1
400
Domain-Driven Design
cassell
2
1k
Other Decks in Programming
See All in Programming
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
1
180
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
1
310
ChromeでローカルLLM
ryu1013
0
120
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
480
sbt 2.0: takeoff
eed3si9n
0
150
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
470
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
210
CodeRabbitの効果検証と過ごしてみた3ヶ月
armondando
0
230
速習iPhone Duo対応
yuukiw00w
2
980
Event is what happens
moro
1
320
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
Jetpack Compose Mechanisms
skydoves
2
730
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Designing for Timeless Needs
cassininazir
1
520
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
560
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
280
A Modern Web Designer's Workflow
chriscoyier
699
190k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
520
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2k
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
370
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1k
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