SlideShare a Scribd company logo
Functional Programming
Concept
By Abdullah Ilhanli
Email: abdullah.ilhanli@gmail.com
Agenda
FP: Funtional Programming
• Prerequisites
• Motivation
• Definition of Function
• Side effect
• Definition of FP
• Lambda Syntax
• Functional Interfaces in Java
• Programming models
• Stream API
• FP Benefits and Drawbacks
• Why we have to use FP
• Do we still need to write imperative?
Prerequisites
• What do you need to better understand?
- Basic Programming(looping, if/else)
- Data structures and algorithms(recursion)
- Design Patterns(strategy, iterator)
Motivation
https://medium.com/@cscalfani/so-you-want-to-be-a-functional-programmer-part-5-c70adc9cf56a
Motivation
Functional Programming vs Object Oriented Program
• Lets watch!
• https://www.youtube.com/watch?v=K_g_xUtydpg
What is a function?
F(x) = x+1
For every x result must be always x+1
Is the result always x+1?
https://dev.to/marpme/basic-functional-programming-with-javascript-2elj
Functional Programming : Side effect
https://www.slideshare.net/EastBancTech/functional-programming-with-c
Side effect
When we are not functional?
All kind of IO operations change the
world. This causes Side Effect.
- File I/O
- Database calls
- Web service calls
What is functional programming
Function as a first class citizen
- You can assign functionality to a
variable
- You can pass functionality to a
procedure
- You can return functionality from
procedure
What is functional programming
https://medium.freecodecamp.org/learning-the-fundamentals-of-functional-programming-425c9fd901c6
Lambda Syntax
https://medium.com/@gelopfalcon/best-practices-when-you-use-lambda-expressions-in-java-f51e96d44b25
Functional Interfaces in Java
https://www.slideshare.net/andreaiacono/java8-39841939
Practice 1: Functional Programming In Java 7
and 8
We will look at basically what kind of problem can we can solve in
functional programming
- interface driven approach
- Anonymous class
- Lambda expression
- https://github.com/ailhanli/functional_programming_by_example/tree/
master/src/main/java/com/ailhanli/practice1
Practice 2: Lazy Execution
In this example we will look at lazy execution using log4j.
https://github.com/ailhanli/functional_programming_by_example/tree/master/s
rc/main/java/com/ailhanli/practice2
Functional Programming: Programming models
https://www.ibm.com/developerworks/library/j-java8idioms1/index.html
Declarative vs Imperative
https://www.slideshare.net/HngHongHi/functional-reactive-programming-74350959
Stream API
https://www.logicbig.com/tutorials/core-java-tutorial/java-util-stream/stream-api-intro.html
Stream API
https://www.exclamationlabs.com/blog/refactoring-for-java-8-streams/
Practice 3: Using Stream API
In this practice we will first look at lazy execution and then using stream api to
solve problem.
https://github.com/ailhanli/functional_programming_by_example/tree/master
/src/main/java/com/ailhanli/practice3
Practice 4: Statistic With Stream API
We will look at grouping account salary sum by their age
https://github.com/ailhanli/functional_programming_by_example/tree/m
aster/src/main/java/com/ailhanli/practice4
Practice 5:
Multithreading by example
In this example we will look at;
-How make stream parallel
-What kind of problem can we face during the parallel execution
https://github.com/ailhanli/functional_programming_by_example/tree/master/src
/main/java/com/ailhanli/practice5
Practice 6:
More examples about Functional
Lets check them
https://github.com/ailhanli/functional_programming_by_example/tree/master/src
/main/java/com/ailhanli/practice6
Functional Programming Benefits and Drawbacks
• Benefits
• Functions have no side effect
• More diffucult to learn than other programming
• Large program can be written with functions tat are relatively easy to test
• Drawbacks
• Less efficient memory usage because of recursion
• Great for programs that are primarily used for analyzing large amounts of
numerical data
Lets watch a video to motivate us more!
• https://www.youtube.com/watch?v=0-wM-bBMYg4
• https://www.youtube.com/watch?v=kJuJU-7_utA
Why we have to use Functional Programming
Why we have to use Functional Programming
- If our project programming language functional, we can write after
now functional
-If our project is not supported, we can make our daily tasks using
java 8 or any other functional
-It is good start to learn Scala for Java developer or F# for Dot net
developer
- It is good start to understand Reactive Programming
Do we still need to write imperative programming?
It depends!
Below link you can see what we can not make functional
https://github.com/ailhanli/functional_programming_by_example/tree/master
/src/main/java/com/ailhanli/practice7
Do you have any question about functional
programming?
Thank you!

More Related Content

PPTX
Scala & Swagger at Wordnik
PPTX
Restful api modeling language
PPTX
Do's and Don'ts of APIs
PDF
APIdays Paris 2019 Backend is the new frontend by Antoine Cheron
PPTX
What is Swagger?
PDF
Java and effective programming. Is it possible? - IAESTE Case Week 2016
PDF
API Testing: Answers to Your Top 3 Questions
PDF
Inside Story: Scratching the Black Box - API
Scala & Swagger at Wordnik
Restful api modeling language
Do's and Don'ts of APIs
APIdays Paris 2019 Backend is the new frontend by Antoine Cheron
What is Swagger?
Java and effective programming. Is it possible? - IAESTE Case Week 2016
API Testing: Answers to Your Top 3 Questions
Inside Story: Scratching the Black Box - API

What's hot (20)

KEY
Expose Yourself! How to Leverage Plugin Extensibility to Delight your Users, ...
PPTX
How to define an api
PPT
Six Steps To Build A Successful API
PPTX
Api Design
PPTX
Rest in practice
PDF
Api First Design
PDF
Native iphone app test automation with appium
PPTX
Golden Rules of API Design
PDF
Moving into API documentation writing
PPT
Ruby on Rails Plugins - Rich Collins
PDF
4 Major Advantages of API Testing
PDF
React For Vikings
PPTX
Polyglot engineering
PPSX
Simple and Effective Development Process For Software v1
PPTX
Building API's
PDF
2016_Jan_Resume_Lyra
PPTX
API design concepts [Intro]
PDF
API Docs Made Right / RAML - Swagger rant
PDF
Building an Eclipse plugin to recommend changes to developers
PDF
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
Expose Yourself! How to Leverage Plugin Extensibility to Delight your Users, ...
How to define an api
Six Steps To Build A Successful API
Api Design
Rest in practice
Api First Design
Native iphone app test automation with appium
Golden Rules of API Design
Moving into API documentation writing
Ruby on Rails Plugins - Rich Collins
4 Major Advantages of API Testing
React For Vikings
Polyglot engineering
Simple and Effective Development Process For Software v1
Building API's
2016_Jan_Resume_Lyra
API design concepts [Intro]
API Docs Made Right / RAML - Swagger rant
Building an Eclipse plugin to recommend changes to developers
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
Ad

Similar to Functional Programming Concept (20)

PDF
S4D437 Col24 Transactional Apps with the ABAP RESTful Application Programming...
PDF
Technical Deep Dive for Transportation Management in SAP S/4HANA, S4TM6 Col14
PDF
Effective programming in Java - Kronospan Job Fair 2016
PDF
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
PPTX
Super simple introduction to REST-APIs (2nd version)
PDF
IBP900 Col06 SAP Cloud Platform Integration for SAP Integrated Business Planning
PDF
Practices and tools for building better APIs
PDF
Practices and tools for building better API (JFall 2013)
PDF
Crafting APIs
PDF
Customizing in SAP S/4HANA Asset Management
PDF
API presentation
PPTX
Azure API Management - why should I care?
PPTX
Patterns for automating API delivery. API conference
PDF
S4133 Col20 Customizing in SAP S/4HANA Asset Management
PDF
SAP HANA Smart Data Integration: Transform and Replicate Data with Ease
PDF
APIS for Startups - Running your Business Inside Out
PDF
apidays Munich 2025 - The Double Life of the API Product Manager, Emmanuel Pa...
PDF
Don't worry be API with Slim framework and Joomla
PPTX
Testing for Logic App Solutions | Integration Monday
PPTX
RubiX ID - API management - Pim Gaemers
S4D437 Col24 Transactional Apps with the ABAP RESTful Application Programming...
Technical Deep Dive for Transportation Management in SAP S/4HANA, S4TM6 Col14
Effective programming in Java - Kronospan Job Fair 2016
Introduction to GraphQL (or How I Learned to Stop Worrying about REST APIs)
Super simple introduction to REST-APIs (2nd version)
IBP900 Col06 SAP Cloud Platform Integration for SAP Integrated Business Planning
Practices and tools for building better APIs
Practices and tools for building better API (JFall 2013)
Crafting APIs
Customizing in SAP S/4HANA Asset Management
API presentation
Azure API Management - why should I care?
Patterns for automating API delivery. API conference
S4133 Col20 Customizing in SAP S/4HANA Asset Management
SAP HANA Smart Data Integration: Transform and Replicate Data with Ease
APIS for Startups - Running your Business Inside Out
apidays Munich 2025 - The Double Life of the API Product Manager, Emmanuel Pa...
Don't worry be API with Slim framework and Joomla
Testing for Logic App Solutions | Integration Monday
RubiX ID - API management - Pim Gaemers
Ad

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Spectroscopy.pptx food analysis technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Electronic commerce courselecture one. Pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation_ Review paper, used for researhc scholars
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Weekly Chronicles - August'25 Week I
20250228 LYD VKU AI Blended-Learning.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation
Programs and apps: productivity, graphics, security and other tools
Spectroscopy.pptx food analysis technology
Machine learning based COVID-19 study performance prediction
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
“AI and Expert System Decision Support & Business Intelligence Systems”
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Electronic commerce courselecture one. Pdf

Functional Programming Concept

Editor's Notes

  • #2: Hello everyone, welcome to functional programming training. before I started, I want to inform that I wont talk details in deep that’s because we don’t have enough time. I will try to explain concept behind the scene. Actually, you dont need to know java. Basic programming knowledge is enough.
  • #3: I will first talk about requirement; what we need to understand, And then motivation; what make FP different than others and why we need And then we will define Function in terms of Math and then programming And then we will talk side effect which changes the world And then we will define functional programming And then we will talk about lambda syntax which comes with java 8 And then we will check already defined functional interfaces in java And then we will focus on programming models And then we will define what Stream API does In Last three slayts are about motivation in more..
  • #4: To understand better, you only need basic programming constructs these are looping, if/else Data structures and algorithms especially recursion And Some of Design patterns strategy and iterator i will explain a bit what they are.
  • #5: Our tiny monkey is our PC. NO actually it is operating system which is a system our programs run on. Assembly is a programming language for microprocessor and devices. It is simply machine language. It is very low level we have to write lots of instructions for simple program Procedural language is good for simple business applications. We have procedures and we call them in order to do our business. Advantage is simple to understand for simple program. Disadvantage is difficult to maintain and extend for real business applications. Object Oriented is good for real business applications. We model our business in terms of objects. SOLID is more important principle in OOP. If you are not using SOLID you are actually writing Object Based Programming. It is now easy to main and extend. Main big disadvantage is writing multithreaded program is really difficult. Functional is our big monkey. It is more readable, easy to extendable and maintain than OOP. Multithreading is also easy. We write less code than Procedural and it uses OOP patterns behind scene. Does it mean we will not use OOP when we program functional? Not really, using OOP and functional together is best programming model. It is actually new way of thinking and not easy to understand. I will explain concept behind the scene in this training! As a result procedural languages uses assembly, OOP uses procedural languages and Functional uses OOP. As a result all of them converted to assembly by the Programming language. So lets get started!
  • #7: In math function is f(x)= x+1 What it means. for every x, result should be x+1 If result is different than x+1, it is not pure function and we can say function has side effect Mathematical functions are pure functions. Programming functions depend.
  • #8: In this example, on the left hand side, for every x and y, result is always x^2+y^2. So it is pure! On the right hand side result is usually different, because date is externally changed and our function will return different result time by time so it has side effect. When do we have side effect in our program?
  • #9: All kind of IO operations including reading/writing file and databases , calling web service etc.. When you do IO during the function execution, function result can be different that because we use operation system disk For instance if file is deleted your program can throw an exception so we can say result is not x+1! Or if database is changed by other programs, our program can return different result.
  • #10: Normally, we define our variable in a program uses simple data types and classes Functional programming means we write our program in terms of functions. What I mean that we can assign our functionality to a variable We can pass our funtion to a procedure We can our function from a procedure
  • #11: What I mean that, a and b can be function.
  • #12: Lambda expression is fundamental of functional of programming Lambda is a implementation of functional interface Functional interface is an interface which has single method only. What is an interface? interface is simply a contract between caller and callee Lambda is shorthand syntax and easy to read than anonymous inner class implementation
  • #13: Java has several built-in functional interfaces. - The main concern should be when reading an interface what this interface takes and returns simply input and output For example Consumer interface take any type of parameter and return nothing. so it consumes. or Function interface take any type of parameter return different types.
  • #14: In demo first we will look at how to change a simple algorithm using strategy pattern and then we will make our algorithm lambda based and see what kind of problem is solved using lambda and what it for.
  • #15: In this example we will look at lazy execution versus eager execution in sample logging
  • #16: In imperative programming model we tell what and tell how to do. We do imperative programming everyday. For instance looping through list, filtering elements calculating sum of filtered elements. In declarative programming model we tell what not how. Programming language will care about the business.
  • #17: In imperative programming you have to write all kind of instructions in order to do your business In declarative programming you have only say what you want like a boss Declarative programming is new way of thinking you only concern your business rather than details about how to do
  • #18: Almost in our all programs we use mostly collections. We iterate collection via iterator pattern and do some calculation. iterator pattern is a pattern which traverse to collection. What Stream API does? We do functional composition with this API. It is an API uses iterator and recursion. with stream API, we write our program uses SQL like operators. all operators take lambda expression as a parameter. It has three components: source, intermediate operators and terminators. Operators take function as an argument. We have focus on what kind of functional interface it needs. **source can be collection, array or file **intermediate operator can be filter, map, sort, distinct **terminator can be collect, toArray, count, reduce If chain hasnt terminator, it wont be execute. so it is lazy lets do more example and understand how can we program functional uses stream API.
  • #19: What a nice picture to understand function composition. Thanks to Toptal In this picture you see that there are many animals goes inside pipe, some them filters based on filter algorithm, then we box filtered ones. finally collect all boxed items. filter actually takes an conditional statement and pass items who satisfy condition. in picture, filter algorithm is our conditional statement. map is take one type of item and create new type of item. in picture, take animal box it. collect is a collectors who carry our boxed animals.
  • #20: In this example we will look at first lazy execution. if a stream hasnt terminator it wont execute. So it is lazy. Then we will develop our previous example uses stream api.
  • #21: Stream API is good for analying data. For example grouping data by age and sum of salary
  • #22: We will see that multithreading is really easy. it takes a second!
  • #23: I will show my daily examples using functional programming.
  • #24: Benefits: because it doesnt have side affect, concurrency is not diffucult. We dont have syncronization problems. We can write a lot of lines of code in a single line and it is more readable and testable We can use functional programming to analyze our data. Drawbacks: It is diffucult to learn and because it uses recursion behind the scene, it uses lots of memory
  • #26: For the old projects which has been developed in earlier version of java for example java 7 or before. we can't use it. if our project in java 8, we can write some parts especially, doing business with collection using java 8. or at least we can write our daily external things in java 8. It is also a first step for learning reactive which will me presented in next week.
  • #27: For collection related jobs, functional programming is good but performance is not better than classic looping structure sometimes. or other things, which are mostly has many details we cannot write functional. example: show one example.