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
510
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
16
Immutability to Save an Ever-Changing World
cassell
0
6
Domain-driven Design Workshop
cassell
1
250
Immutability to save an ever-changing world
cassell
3
420
Introduction to Domain-Driven Design in PHP - ZendCon & OpenEnterprise 2018
cassell
3
650
Immutability to Save an Ever-Changing World - PHP Benelux 2018
cassell
1
520
Domain-driven Design in PHP - PHP Benelux 2018
cassell
1
150
php[world] 2017 Domain-Driven Design Workshop
cassell
1
270
Domain-Driven Design
cassell
2
830
Other Decks in Programming
See All in Programming
Introduction to GitOps
hwchiu
0
110
Jetpack for KMP
fornewid
1
290
TiDB Serverless ~理想のServerless DBを考える~
soso_15315
1
160
Composing an API the *right* way (Droidcon Berlin 2024)
zsmb
1
450
OpenAI/Gemini APIを使って EPUBを翻訳するCLIツールをつくってみた
tomiyan
0
790
小さな開発会社を作った理由
polidog
0
1.9k
Play Billing Library 7.0.0 変更点まとめ@potatotips#88
kako351
0
160
APIのない大学ログインWebサービスをWKWebViewとJavaScriptでアプリ化した話
akidon0000
1
330
Exploring the Gradually Lost Technical Skills in the Cloud Native Era
hwchiu
2
3.9k
ピグパーティにおけるMongoDB CommunityバージョンからAtlasへの移行事例
10969hotaka
0
130
CSC307 Lecture 05
javiergs
PRO
0
210
DynamoDB コスト最適化っぽいことの基本 with Terraform
kuro_kurorrr
2
250
Featured
See All Featured
Become a Pro
speakerdeck
PRO
15
4.8k
How GitHub (no longer) Works
holman
305
140k
Build The Right Thing And Hit Your Dates
maggiecrowley
28
2.2k
In The Pink: A Labor of Love
frogandcode
139
22k
The Illustrated Children's Guide to Kubernetes
chrisshort
39
47k
Being A Developer After 40
akosma
72
580k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
19k
Thoughts on Productivity
jonyablonski
64
4.1k
Into the Great Unknown - MozCon
thekraken
20
1.3k
Unsuck your backbone
ammeep
666
57k
Documentation Writing (for coders)
carmenintech
63
4.2k
A Modern Web Designer's Workflow
chriscoyier
689
190k
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