SlideShare a Scribd company logo
Umut IŞIK
Functional Programming 1
In PHP
1. Introduction
2. The Benefits
3. Basics In PHP
1. Recursion
2. Map , Reduce And Filter
3. Lambda
4. Closure
4. Final Example
5. Resources
Table Of Contents
According to Wikipedia
… a style of building the structure and elements of computer
programs, that treats computation as the evaluation of
mathematical functions and avoids changing state and mutable
data.
1. Introduction
According to Haskellwiki
..programs are executed by evaluating expressions, … FP
(Functional programming) typically avoids using mutable state…
…functions are first-class, which means that they are treated like
any other values and can be passed as arguments to other
functions or be returned as a result of a function.
1. Introduction
According to Simon Hoywell
Programming in functional way is essentially coding without any
assigment of values.
Values can be passed from function to function as arguments
and return values.
1. Introduction
Summary
Two main terms
▪Avoid value assignment
▪Use functions as parameters & return values
1. Introduction
Simple Sample
1. Introduction
History
▪Lisp for scientific computers in the late 1950s
▪Scheme and Dylan were later attempts to simplify and improve
Lisp
▪In the 1970s, ML was created
▪The Haskell language began with a consensus in 1987 to form
an open standard for functional programming
1. Introduction
History (What happened?)
▪A significant change in the modern computing platform with
multi-cores
▪Need of parallel processing
1. Introduction
What can humble function do better?
Functional programing is not just about using functions
everywhere. It changes the paradigm.
2. The Benefits
Changing the paradigm?
▪Avoid changing state
▪Break problems down to smallest units
▪Reusable function for smallest units
▪Keep functions as short as possible (even one line)
▪Create too small functions that are not worth naming
▪Remove control statements (hardest part ☺ )
2. The Benefits
Changing the paradigm?
Let’s think about a simple problem «getting in the house».
Special thanks to Alexander Steshenko. (Resources #4)
2. The Benefits
Changing the paradigm?
Imperative getting into the house solution:
1. get the keys out of the pocket
2. pick the right key
3. open the door with the key
4. enter the house
2. The Benefits
Changing the paradigm?
Functional getting into the house solution:
▪enter the house
▪through the door opened
▪with the right key
▪chosen from all the keys you get out of the pocket
2. The Benefits
Avoid value assignment
▪No state on runtime
▪Immutable state
▪Code correctness is of special importance
▪More time for algorythm
▪No mocking for global state (so testing is easy ☺ )
2. The Benefits
Functions as parameters and return values
▪Substituting functions with values for tests (Referential
transparency)
▪FP pushes you to create reusable functions
▪Higher level of abstractions
2. The Benefits
Performance
▪Concurrency/Paralel processing
▪Order of execution is not important (side effect free functions ☺
)
2. The Benefits
PHP is inherently imperative but
▪It supports basics of FP
▪It has lambda function
▪You can protect your code from changing state
▪There are many libraries for FP
3. Basics In PHP
Recursion
▪To avoid using control statements (loops)
▪Be carefull about stop condition
▪Be carefull about variable assignments in recursive function
3. Basics In PHP
Recursion
Total of price of a shopping cart
3. Basics In PHP
Map , Reduce and Filter
▪Map function processes a key/value pair to generate a set of
intermediate key/value pairs
▪Reduce function merges all intermediate values associated with
the same intermediate key
▪Filter function creates a subset by applying a callback function
3. Basics In PHP
Map , Reduce and Filter
▪array_map() for map technique
▪array_reduce() for reduce technique
▪array_filter() for reduce technique
3. Basics In PHP
Map , Reduce and Filter
Map technique for applying discount to shopping cart
3. Basics In PHP
Map , Reduce and Filter
Reduce technique for calculating total price of shopping cart
3. Basics In PHP
Map , Reduce and Filter
Filter technique for filtering products according to region from
shopping cart
3. Basics In PHP
Lambda
A function without a formal identifier or name
3. Basics In PHP
Closure
“An object is data with functions. A closure is a function with
data.” — John D. Cook
3. Basics In PHP
Closure
▪Similar role in FP as objects perform in OOP
▪In PHP a closure is an instance of internal Closure class
▪Very similar to Lambda
▪«use» clause passes variables or closures/functions into closure
3. Basics In PHP
Closure
Calculate product price by applying personal discount
3. Basics In PHP
A shopping cart implementation
4. Final Example
1. http://en.wikipedia.org/wiki/Functional_programming
2. http://www.haskell.org/haskellwiki/Functional_programming
3. http://www.functionalphp.com/
4. http://blog.lcf.name/2011/12/functional-programming-in-php.
html
5. Resources
Ad

More Related Content

What's hot (20)

Programming in c by pkv
Programming in c by pkvProgramming in c by pkv
Programming in c by pkv
Pramod Vishwakarma
 
user defined function
user defined functionuser defined function
user defined function
King Kavin Patel
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
Appili Vamsi Krishna
 
predefined and user defined functions
predefined and user defined functionspredefined and user defined functions
predefined and user defined functions
Swapnil Yadav
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
Praveen M Jigajinni
 
structured programming
structured programmingstructured programming
structured programming
Ahmad54321
 
Functions and tasks in verilog
Functions and tasks in verilogFunctions and tasks in verilog
Functions and tasks in verilog
Nallapati Anindra
 
Procedure n functions
Procedure n functionsProcedure n functions
Procedure n functions
Khadija Parween
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 
C FUNCTIONS
C FUNCTIONSC FUNCTIONS
C FUNCTIONS
TeenaGeorge15
 
Functions and return type
Functions and return typeFunctions and return type
Functions and return type
baabtra.com - No. 1 supplier of quality freshers
 
Function and types
Function  and typesFunction  and types
Function and types
Sherin Fathima
 
Built in function
Built in functionBuilt in function
Built in function
MD. Rayhanul Islam Sayket
 
Function in C Language
Function in C Language Function in C Language
Function in C Language
programmings guru
 
Modular programming
Modular programmingModular programming
Modular programming
RoshanMaharjan13
 
Functions
FunctionsFunctions
Functions
Online
 
Functions
FunctionsFunctions
Functions
Lakshmi Sarvani Videla
 
Verilog Tasks and functions
Verilog Tasks and functionsVerilog Tasks and functions
Verilog Tasks and functions
Vinchipsytm Vlsitraining
 
Functional Python Webinar from October 22nd, 2014
Functional Python Webinar from October 22nd, 2014Functional Python Webinar from October 22nd, 2014
Functional Python Webinar from October 22nd, 2014
Reuven Lerner
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 

Viewers also liked (20)

Using mySQL in PHP
Using mySQL in PHPUsing mySQL in PHP
Using mySQL in PHP
Mike Crabb
 
JQuery-Tutorial
 JQuery-Tutorial JQuery-Tutorial
JQuery-Tutorial
tutorialsruby
 
Financial intelligent for start ups
Financial intelligent for start upsFinancial intelligent for start ups
Financial intelligent for start ups
jubril
 
Fcp lecture 01
Fcp lecture 01Fcp lecture 01
Fcp lecture 01
educationfront
 
Presentation & Pitching tips
Presentation & Pitching tipsPresentation & Pitching tips
Presentation & Pitching tips
ABrandNewYou
 
Microsoft excel beginner
Microsoft excel beginnerMicrosoft excel beginner
Microsoft excel beginner
denstar ricardo silalahi
 
Intro to php
Intro to phpIntro to php
Intro to php
Sp Singh
 
How to Use Publicity to Grow Your Startup
How to Use Publicity to Grow Your StartupHow to Use Publicity to Grow Your Startup
How to Use Publicity to Grow Your Startup
Joy Schoffler
 
Why Learn PHP Programming?
Why Learn PHP Programming?Why Learn PHP Programming?
Why Learn PHP Programming?
XtreemHeights
 
Intro to PHP for Beginners
Intro to PHP for BeginnersIntro to PHP for Beginners
Intro to PHP for Beginners
mtlgirlgeeks
 
Computer Programming- Lecture 10
Computer Programming- Lecture 10Computer Programming- Lecture 10
Computer Programming- Lecture 10
Dr. Md. Shohel Sayeed
 
Excel training for beginners
Excel training for beginnersExcel training for beginners
Excel training for beginners
Parul Sharan
 
phpTutorial1
phpTutorial1phpTutorial1
phpTutorial1
tutorialsruby
 
Beating the decline of the Facebook Organic Reach - KRDS singapore
Beating the decline of the Facebook Organic Reach - KRDS singapore Beating the decline of the Facebook Organic Reach - KRDS singapore
Beating the decline of the Facebook Organic Reach - KRDS singapore
KRDS
 
Computer Programming- Lecture 9
Computer Programming- Lecture 9Computer Programming- Lecture 9
Computer Programming- Lecture 9
Dr. Md. Shohel Sayeed
 
How to present your business plan to investors
How to present your business plan to investorsHow to present your business plan to investors
How to present your business plan to investors
The Hatch
 
Comp 107 cep ii
Comp 107 cep iiComp 107 cep ii
Comp 107 cep ii
Bala Ganesh
 
Comp 107chp 1
Comp 107chp 1Comp 107chp 1
Comp 107chp 1
Bala Ganesh
 
9 Tips For Building An Internal Social Media Team
9 Tips For Building An Internal Social Media Team9 Tips For Building An Internal Social Media Team
9 Tips For Building An Internal Social Media Team
Ogilvy Consulting
 
Excel for beginners class 1
Excel for beginners class 1Excel for beginners class 1
Excel for beginners class 1
Carlstadt Public Library
 
Using mySQL in PHP
Using mySQL in PHPUsing mySQL in PHP
Using mySQL in PHP
Mike Crabb
 
Financial intelligent for start ups
Financial intelligent for start upsFinancial intelligent for start ups
Financial intelligent for start ups
jubril
 
Presentation & Pitching tips
Presentation & Pitching tipsPresentation & Pitching tips
Presentation & Pitching tips
ABrandNewYou
 
Intro to php
Intro to phpIntro to php
Intro to php
Sp Singh
 
How to Use Publicity to Grow Your Startup
How to Use Publicity to Grow Your StartupHow to Use Publicity to Grow Your Startup
How to Use Publicity to Grow Your Startup
Joy Schoffler
 
Why Learn PHP Programming?
Why Learn PHP Programming?Why Learn PHP Programming?
Why Learn PHP Programming?
XtreemHeights
 
Intro to PHP for Beginners
Intro to PHP for BeginnersIntro to PHP for Beginners
Intro to PHP for Beginners
mtlgirlgeeks
 
Excel training for beginners
Excel training for beginnersExcel training for beginners
Excel training for beginners
Parul Sharan
 
Beating the decline of the Facebook Organic Reach - KRDS singapore
Beating the decline of the Facebook Organic Reach - KRDS singapore Beating the decline of the Facebook Organic Reach - KRDS singapore
Beating the decline of the Facebook Organic Reach - KRDS singapore
KRDS
 
How to present your business plan to investors
How to present your business plan to investorsHow to present your business plan to investors
How to present your business plan to investors
The Hatch
 
9 Tips For Building An Internal Social Media Team
9 Tips For Building An Internal Social Media Team9 Tips For Building An Internal Social Media Team
9 Tips For Building An Internal Social Media Team
Ogilvy Consulting
 
Ad

Similar to Functional Programming In PHP I (20)

Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
KarthickT28
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programming
Dhaval Dalal
 
Python functional programming
Python functional programmingPython functional programming
Python functional programming
Geison Goes
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programming
Konrad Szydlo
 
(3) cpp procedural programming
(3) cpp procedural programming(3) cpp procedural programming
(3) cpp procedural programming
Nico Ludwig
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
Steve Zhang
 
PLSQL-OO [SOUG 2022].pptx
PLSQL-OO [SOUG 2022].pptxPLSQL-OO [SOUG 2022].pptx
PLSQL-OO [SOUG 2022].pptx
Richard Martens
 
Functional programming in python
Functional programming in pythonFunctional programming in python
Functional programming in python
Edward D. Weinberger
 
Functional programming in python
Functional programming in pythonFunctional programming in python
Functional programming in python
Edward D. Weinberger
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
KhurramKhan173
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
RichardWarburton
 
Funtional Programming
Funtional ProgrammingFuntional Programming
Funtional Programming
Girish Khanzode
 
_Python_ Functions _and_ Libraries_.pptx
_Python_ Functions _and_ Libraries_.pptx_Python_ Functions _and_ Libraries_.pptx
_Python_ Functions _and_ Libraries_.pptx
yaramahsoob
 
Functional Programming in Ruby
Functional Programming in RubyFunctional Programming in Ruby
Functional Programming in Ruby
Alex Teut
 
Functional Paradigm.pptx
Functional Paradigm.pptxFunctional Paradigm.pptx
Functional Paradigm.pptx
FurretMaster
 
Savitch Ch 04
Savitch Ch 04Savitch Ch 04
Savitch Ch 04
Terry Yoast
 
Savitch Ch 04
Savitch Ch 04Savitch Ch 04
Savitch Ch 04
Terry Yoast
 
Intro to JavaScript - Week 2: Function
Intro to JavaScript - Week 2: FunctionIntro to JavaScript - Week 2: Function
Intro to JavaScript - Week 2: Function
Jeongbae Oh
 
Basics of cpp
Basics of cppBasics of cpp
Basics of cpp
vinay chauhan
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNext
Unfold UI
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
KarthickT28
 
Booting into functional programming
Booting into functional programmingBooting into functional programming
Booting into functional programming
Dhaval Dalal
 
Python functional programming
Python functional programmingPython functional programming
Python functional programming
Geison Goes
 
Introduction to functional programming
Introduction to functional programmingIntroduction to functional programming
Introduction to functional programming
Konrad Szydlo
 
(3) cpp procedural programming
(3) cpp procedural programming(3) cpp procedural programming
(3) cpp procedural programming
Nico Ludwig
 
The joy of functional programming
The joy of functional programmingThe joy of functional programming
The joy of functional programming
Steve Zhang
 
PLSQL-OO [SOUG 2022].pptx
PLSQL-OO [SOUG 2022].pptxPLSQL-OO [SOUG 2022].pptx
PLSQL-OO [SOUG 2022].pptx
Richard Martens
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
KhurramKhan173
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
RichardWarburton
 
_Python_ Functions _and_ Libraries_.pptx
_Python_ Functions _and_ Libraries_.pptx_Python_ Functions _and_ Libraries_.pptx
_Python_ Functions _and_ Libraries_.pptx
yaramahsoob
 
Functional Programming in Ruby
Functional Programming in RubyFunctional Programming in Ruby
Functional Programming in Ruby
Alex Teut
 
Functional Paradigm.pptx
Functional Paradigm.pptxFunctional Paradigm.pptx
Functional Paradigm.pptx
FurretMaster
 
Intro to JavaScript - Week 2: Function
Intro to JavaScript - Week 2: FunctionIntro to JavaScript - Week 2: Function
Intro to JavaScript - Week 2: Function
Jeongbae Oh
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNext
Unfold UI
 
Ad

More from Umut IŞIK (20)

Açık Kaynağa Nasıl Katkı Yapabiliriz?
Açık Kaynağa Nasıl Katkı Yapabiliriz?Açık Kaynağa Nasıl Katkı Yapabiliriz?
Açık Kaynağa Nasıl Katkı Yapabiliriz?
Umut IŞIK
 
Php projelerinde ci_uygulama
Php projelerinde ci_uygulamaPhp projelerinde ci_uygulama
Php projelerinde ci_uygulama
Umut IŞIK
 
Açık Kaynağa Nasıl Katkı Yapabiliriz?
Açık Kaynağa Nasıl Katkı Yapabiliriz?Açık Kaynağa Nasıl Katkı Yapabiliriz?
Açık Kaynağa Nasıl Katkı Yapabiliriz?
Umut IŞIK
 
A Ci Experience
A Ci ExperienceA Ci Experience
A Ci Experience
Umut IŞIK
 
BBS Flyers 08/2016
BBS Flyers 08/2016BBS Flyers 08/2016
BBS Flyers 08/2016
Umut IŞIK
 
BBS Flyers 07/2016
BBS Flyers 07/2016BBS Flyers 07/2016
BBS Flyers 07/2016
Umut IŞIK
 
BBS Flyers 05/2016
BBS Flyers 05/2016BBS Flyers 05/2016
BBS Flyers 05/2016
Umut IŞIK
 
BBS Flyers 03/2016
BBS Flyers 03/2016BBS Flyers 03/2016
BBS Flyers 03/2016
Umut IŞIK
 
BBS Flyers 02/2016
BBS Flyers 02/2016BBS Flyers 02/2016
BBS Flyers 02/2016
Umut IŞIK
 
BBS Flyers 01/2016
BBS Flyers 01/2016BBS Flyers 01/2016
BBS Flyers 01/2016
Umut IŞIK
 
BBS Flyers 12/2015
BBS Flyers 12/2015BBS Flyers 12/2015
BBS Flyers 12/2015
Umut IŞIK
 
BBS Flyers 11/2015
BBS Flyers 11/2015BBS Flyers 11/2015
BBS Flyers 11/2015
Umut IŞIK
 
BBS Flyers 10/2015
BBS Flyers 10/2015BBS Flyers 10/2015
BBS Flyers 10/2015
Umut IŞIK
 
BBS Flyers 09/2015
BBS Flyers 09/2015BBS Flyers 09/2015
BBS Flyers 09/2015
Umut IŞIK
 
Ionic
IonicIonic
Ionic
Umut IŞIK
 
BBS Flyers 08/2015
BBS Flyers 08/2015BBS Flyers 08/2015
BBS Flyers 08/2015
Umut IŞIK
 
BBS Flyers-07-2015
BBS Flyers-07-2015BBS Flyers-07-2015
BBS Flyers-07-2015
Umut IŞIK
 
BBS Flyers 06/2015
BBS Flyers 06/2015BBS Flyers 06/2015
BBS Flyers 06/2015
Umut IŞIK
 
BBS Flyers 05/2015
BBS Flyers 05/2015BBS Flyers 05/2015
BBS Flyers 05/2015
Umut IŞIK
 
BBS Flyers 04/2015
BBS Flyers 04/2015BBS Flyers 04/2015
BBS Flyers 04/2015
Umut IŞIK
 
Açık Kaynağa Nasıl Katkı Yapabiliriz?
Açık Kaynağa Nasıl Katkı Yapabiliriz?Açık Kaynağa Nasıl Katkı Yapabiliriz?
Açık Kaynağa Nasıl Katkı Yapabiliriz?
Umut IŞIK
 
Php projelerinde ci_uygulama
Php projelerinde ci_uygulamaPhp projelerinde ci_uygulama
Php projelerinde ci_uygulama
Umut IŞIK
 
Açık Kaynağa Nasıl Katkı Yapabiliriz?
Açık Kaynağa Nasıl Katkı Yapabiliriz?Açık Kaynağa Nasıl Katkı Yapabiliriz?
Açık Kaynağa Nasıl Katkı Yapabiliriz?
Umut IŞIK
 
A Ci Experience
A Ci ExperienceA Ci Experience
A Ci Experience
Umut IŞIK
 
BBS Flyers 08/2016
BBS Flyers 08/2016BBS Flyers 08/2016
BBS Flyers 08/2016
Umut IŞIK
 
BBS Flyers 07/2016
BBS Flyers 07/2016BBS Flyers 07/2016
BBS Flyers 07/2016
Umut IŞIK
 
BBS Flyers 05/2016
BBS Flyers 05/2016BBS Flyers 05/2016
BBS Flyers 05/2016
Umut IŞIK
 
BBS Flyers 03/2016
BBS Flyers 03/2016BBS Flyers 03/2016
BBS Flyers 03/2016
Umut IŞIK
 
BBS Flyers 02/2016
BBS Flyers 02/2016BBS Flyers 02/2016
BBS Flyers 02/2016
Umut IŞIK
 
BBS Flyers 01/2016
BBS Flyers 01/2016BBS Flyers 01/2016
BBS Flyers 01/2016
Umut IŞIK
 
BBS Flyers 12/2015
BBS Flyers 12/2015BBS Flyers 12/2015
BBS Flyers 12/2015
Umut IŞIK
 
BBS Flyers 11/2015
BBS Flyers 11/2015BBS Flyers 11/2015
BBS Flyers 11/2015
Umut IŞIK
 
BBS Flyers 10/2015
BBS Flyers 10/2015BBS Flyers 10/2015
BBS Flyers 10/2015
Umut IŞIK
 
BBS Flyers 09/2015
BBS Flyers 09/2015BBS Flyers 09/2015
BBS Flyers 09/2015
Umut IŞIK
 
BBS Flyers 08/2015
BBS Flyers 08/2015BBS Flyers 08/2015
BBS Flyers 08/2015
Umut IŞIK
 
BBS Flyers-07-2015
BBS Flyers-07-2015BBS Flyers-07-2015
BBS Flyers-07-2015
Umut IŞIK
 
BBS Flyers 06/2015
BBS Flyers 06/2015BBS Flyers 06/2015
BBS Flyers 06/2015
Umut IŞIK
 
BBS Flyers 05/2015
BBS Flyers 05/2015BBS Flyers 05/2015
BBS Flyers 05/2015
Umut IŞIK
 
BBS Flyers 04/2015
BBS Flyers 04/2015BBS Flyers 04/2015
BBS Flyers 04/2015
Umut IŞIK
 

Recently uploaded (20)

Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Mastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdfMastering Advance Window Functions in SQL.pdf
Mastering Advance Window Functions in SQL.pdf
Spiral Mantra
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
TrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token ListingTrsLabs Consultants - DeFi, WEb3, Token Listing
TrsLabs Consultants - DeFi, WEb3, Token Listing
Trs Labs
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
Unlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive GuideUnlocking the Power of IVR: A Comprehensive Guide
Unlocking the Power of IVR: A Comprehensive Guide
vikasascentbpo
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 

Functional Programming In PHP I

  • 2. 1. Introduction 2. The Benefits 3. Basics In PHP 1. Recursion 2. Map , Reduce And Filter 3. Lambda 4. Closure 4. Final Example 5. Resources Table Of Contents
  • 3. According to Wikipedia … a style of building the structure and elements of computer programs, that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. 1. Introduction
  • 4. According to Haskellwiki ..programs are executed by evaluating expressions, … FP (Functional programming) typically avoids using mutable state… …functions are first-class, which means that they are treated like any other values and can be passed as arguments to other functions or be returned as a result of a function. 1. Introduction
  • 5. According to Simon Hoywell Programming in functional way is essentially coding without any assigment of values. Values can be passed from function to function as arguments and return values. 1. Introduction
  • 6. Summary Two main terms ▪Avoid value assignment ▪Use functions as parameters & return values 1. Introduction
  • 8. History ▪Lisp for scientific computers in the late 1950s ▪Scheme and Dylan were later attempts to simplify and improve Lisp ▪In the 1970s, ML was created ▪The Haskell language began with a consensus in 1987 to form an open standard for functional programming 1. Introduction
  • 9. History (What happened?) ▪A significant change in the modern computing platform with multi-cores ▪Need of parallel processing 1. Introduction
  • 10. What can humble function do better? Functional programing is not just about using functions everywhere. It changes the paradigm. 2. The Benefits
  • 11. Changing the paradigm? ▪Avoid changing state ▪Break problems down to smallest units ▪Reusable function for smallest units ▪Keep functions as short as possible (even one line) ▪Create too small functions that are not worth naming ▪Remove control statements (hardest part ☺ ) 2. The Benefits
  • 12. Changing the paradigm? Let’s think about a simple problem «getting in the house». Special thanks to Alexander Steshenko. (Resources #4) 2. The Benefits
  • 13. Changing the paradigm? Imperative getting into the house solution: 1. get the keys out of the pocket 2. pick the right key 3. open the door with the key 4. enter the house 2. The Benefits
  • 14. Changing the paradigm? Functional getting into the house solution: ▪enter the house ▪through the door opened ▪with the right key ▪chosen from all the keys you get out of the pocket 2. The Benefits
  • 15. Avoid value assignment ▪No state on runtime ▪Immutable state ▪Code correctness is of special importance ▪More time for algorythm ▪No mocking for global state (so testing is easy ☺ ) 2. The Benefits
  • 16. Functions as parameters and return values ▪Substituting functions with values for tests (Referential transparency) ▪FP pushes you to create reusable functions ▪Higher level of abstractions 2. The Benefits
  • 17. Performance ▪Concurrency/Paralel processing ▪Order of execution is not important (side effect free functions ☺ ) 2. The Benefits
  • 18. PHP is inherently imperative but ▪It supports basics of FP ▪It has lambda function ▪You can protect your code from changing state ▪There are many libraries for FP 3. Basics In PHP
  • 19. Recursion ▪To avoid using control statements (loops) ▪Be carefull about stop condition ▪Be carefull about variable assignments in recursive function 3. Basics In PHP
  • 20. Recursion Total of price of a shopping cart 3. Basics In PHP
  • 21. Map , Reduce and Filter ▪Map function processes a key/value pair to generate a set of intermediate key/value pairs ▪Reduce function merges all intermediate values associated with the same intermediate key ▪Filter function creates a subset by applying a callback function 3. Basics In PHP
  • 22. Map , Reduce and Filter ▪array_map() for map technique ▪array_reduce() for reduce technique ▪array_filter() for reduce technique 3. Basics In PHP
  • 23. Map , Reduce and Filter Map technique for applying discount to shopping cart 3. Basics In PHP
  • 24. Map , Reduce and Filter Reduce technique for calculating total price of shopping cart 3. Basics In PHP
  • 25. Map , Reduce and Filter Filter technique for filtering products according to region from shopping cart 3. Basics In PHP
  • 26. Lambda A function without a formal identifier or name 3. Basics In PHP
  • 27. Closure “An object is data with functions. A closure is a function with data.” — John D. Cook 3. Basics In PHP
  • 28. Closure ▪Similar role in FP as objects perform in OOP ▪In PHP a closure is an instance of internal Closure class ▪Very similar to Lambda ▪«use» clause passes variables or closures/functions into closure 3. Basics In PHP
  • 29. Closure Calculate product price by applying personal discount 3. Basics In PHP
  • 30. A shopping cart implementation 4. Final Example
  • 31. 1. http://en.wikipedia.org/wiki/Functional_programming 2. http://www.haskell.org/haskellwiki/Functional_programming 3. http://www.functionalphp.com/ 4. http://blog.lcf.name/2011/12/functional-programming-in-php. html 5. Resources