SlideShare a Scribd company logo
Introduction to
Functional
Programming
◦ Motivations
◦ Definitions
▫ Values
▫ Types
▫ Functions
◦ Resources
AGENDA
Motivations
Why you might want to use functional programming
1
Object-Oriented Programming
Everything is an object
◦ State
◦ Behavior
You can consider objects as (badly
designed) state machines with a wide
space of states and transitions
Object-Oriented Programming
◦ Reasoning about the code becomes
complex quickly
◦ Unit tests to the rescue
▫ 100% coverage
▫ Always more tests !
Functional Programming
◦ Write expressive code.
◦ Write less code.
◦ Write performant code.
◦ Write code that we can easily
reason about.
The main goals are to reduce the input
and state space and ease reasoning.
Values
Building blocks of Functional Programming
2
“
If you say “a” is 5, you can’t say it’s
something else later because you just
said it was 5. What are you, some kind of
liar?
Miran Lipovaca - http://learnyouahaskell.com/
Immutability
A value or data structure cannot be
modified after its initialization
Values
Immutable
◦ You assign a value and can’t
reassign another one.
Data structure are immutable too. To
update them, you return a new
instance with the updated state.
Values are immutable - Java
Values are immutable - Scala
Data structures are immutable - Java
Data structures are immutable - Scala
◦ Immutability eliminates state transition
▫ Passing values and data structure
reference is safe
For lists: Functional languages reuse data and will
not duplicate values.
Immutability
Types
Building blocks of Functional Programming
2
Types
◦ Classification of values
◦ The compiler can verify the correctness of
values with types
Types
Functions
Building blocks of Functional Programming
3
f(x) = y
Always. Always. Always. Always.
◦ Take an argument and produce a result
◦ Pure functions do not have side-effects
▫ Change external state
▫ Modify a value
▫ Throw an exception
▫ Read from sdtin
▫ Write to disk
Functions
“
Functional programming is a restriction
on how we write programs, but not on
what we express.
Paul Chiusano and Rúnar Bjarnason - Functional Programming in Scala
◦ Change external state
▫ Just don’t do it
◦ Modify a value
▫ Remember: immutable
◦ Throwing exception
▫ Return them as sentinel values
▫ Return an [Option] value
▫ Return an [Either] value
◦ I/O
▫ Most functional languages have the IO
monad1
Alternative to side-effects
1 http://en.wikipedia.org/wiki/Monad_%28functional_programming%29#The_I.2FO_monad
Functions example in Java
Functions example in Scala
Optional type example
Avoid loops
Recursion can do the job.
Tail-recursion example
Not tail-recursion example
What is the last executed statement ?
Tail-recursion example
* This one comes from my editor
High order functions
Functions that return a function and/or take
function(s) as parameters.
High-order functions in Java
High-order functions in Java
High-order functions in Scala
Useful combinators/High-order functions
map: Applies a function to each element of a list.
flatMap: Applies a function to a collection and
flattens the result by one level.
fold: Combines elements of a collection by
applying a given function recursively.
filter: Returns only the element that passes a
truth test.
Resources
◦ Félix-Étienne Trépanier - Confoo slides:
http://www.slideshare.net/felixtrepanier/intro-to-
functional-programming-confoo
◦ Martin Odersky - Functional Programming Principles in
Scala: https://www.coursera.org/course/progfun
◦ Miran Lipocava - Learn you a Haskell for Great Good !:
http://learnyouahaskell.com/
◦ JavaScript allongé:
https://leanpub.com/javascriptallongesix
◦ Paul Chiusano and Runr Bjarnason - Functional
Programming in Scala:
http://www.manning.com/bjarnason/
Thanks!
ANY QUESTIONS?
You can find me at
@NyloAndry
ny.fanilo@gmail.com
CREDITS
Special thanks to all the people who made and
released these awesome resources for free:
◦ Presentation template by SlidesCarnival
◦ Photographs by Unsplash
Code screenshots:
http://www.slideshare.net/felixtrepanier/intro-to-
functional-programming-confoo

More Related Content

PDF
Why should a Java programmer shifts towards Functional Programming Paradigm
PDF
Functional programming
PDF
Functional Programming in Ruby
PPT
JavaScript Introductin to Functions
PDF
Functions, anonymous functions and the function type
PDF
Introduction to Higher Order Functions in Scala
PPTX
XII Computer Science- Chapter 1-Function
PPTX
Functional Programming in Java
Why should a Java programmer shifts towards Functional Programming Paradigm
Functional programming
Functional Programming in Ruby
JavaScript Introductin to Functions
Functions, anonymous functions and the function type
Introduction to Higher Order Functions in Scala
XII Computer Science- Chapter 1-Function
Functional Programming in Java

What's hot (20)

PDF
Functional Programming For All - Scala Matsuri 2016
PDF
Intro to Functional Programming @ Scala Montreal
PPTX
scope of python
PPTX
Monolithic and Procedural Programming
PPTX
05 functional programming
PPTX
Introduction to functional programming with java 8
PPTX
WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD?
PDF
Angular directives and pipes
PDF
Functional Programming in Java
PPTX
Why Functional Programming So Hard?
PDF
Forward JS 2017 | SF | Write applications as State Machines
PDF
Functional programming in scala
PPTX
Pure functions and usage in Angular
PDF
Functional programming with Java 8
PPTX
Introduction to JSX
PPTX
Inline functions & macros
PDF
Test Driven Development
PDF
Value Objects
PPTX
Programming in python w6
PPTX
Operators in java By cheena
Functional Programming For All - Scala Matsuri 2016
Intro to Functional Programming @ Scala Montreal
scope of python
Monolithic and Procedural Programming
05 functional programming
Introduction to functional programming with java 8
WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD?
Angular directives and pipes
Functional Programming in Java
Why Functional Programming So Hard?
Forward JS 2017 | SF | Write applications as State Machines
Functional programming in scala
Pure functions and usage in Angular
Functional programming with Java 8
Introduction to JSX
Inline functions & macros
Test Driven Development
Value Objects
Programming in python w6
Operators in java By cheena
Ad

Similar to Introduction to Functional programming (20)

PDF
Intro to functional programming - Confoo
PPTX
Functional programming f#
PPTX
The joy of functional programming
PPTX
When life gives you functions make functional programs!
PDF
Functional Programming In Scala Second Edition Meap V08 2nd All Chapters Avai...
PDF
Introduction to functional programming (In Arabic)
PDF
Functional programming scala_mod
PPTX
From Imperative to Functional Programming (for Absolute Beginners)
PDF
Functional programming in Scala
PPTX
Intro to Functional Programming
PPTX
Functional Paradigm.pptx
PDF
Introduction to functional programming
PPTX
Introduction to Functional Programming
PDF
Becoming Functional Steps For Transforming Into A Functional Programmer Joshu...
PDF
Functional Programming in Scala: Notes
PDF
Functional Programming Essentials
PDF
A (very brief) into to Functional Programming
PPTX
Vendredi Tech_ la programmation fonctionnelle.pptx
PDF
Functional Programming in Scala 1st Edition Paul Chiusano
PDF
Teach Yourself some Functional Programming with Scala
Intro to functional programming - Confoo
Functional programming f#
The joy of functional programming
When life gives you functions make functional programs!
Functional Programming In Scala Second Edition Meap V08 2nd All Chapters Avai...
Introduction to functional programming (In Arabic)
Functional programming scala_mod
From Imperative to Functional Programming (for Absolute Beginners)
Functional programming in Scala
Intro to Functional Programming
Functional Paradigm.pptx
Introduction to functional programming
Introduction to Functional Programming
Becoming Functional Steps For Transforming Into A Functional Programmer Joshu...
Functional Programming in Scala: Notes
Functional Programming Essentials
A (very brief) into to Functional Programming
Vendredi Tech_ la programmation fonctionnelle.pptx
Functional Programming in Scala 1st Edition Paul Chiusano
Teach Yourself some Functional Programming with Scala
Ad

Recently uploaded (20)

PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
medical staffing services at VALiNTRY
PDF
Nekopoi APK 2025 free lastest update
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Introduction to Artificial Intelligence
PPTX
ai tools demonstartion for schools and inter college
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Transform Your Business with a Software ERP System
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
CHAPTER 2 - PM Management and IT Context
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Wondershare Filmora 15 Crack With Activation Key [2025
Odoo POS Development Services by CandidRoot Solutions
How to Migrate SBCGlobal Email to Yahoo Easily
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
medical staffing services at VALiNTRY
Nekopoi APK 2025 free lastest update
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Softaken Excel to vCard Converter Software.pdf
Introduction to Artificial Intelligence
ai tools demonstartion for schools and inter college
Upgrade and Innovation Strategies for SAP ERP Customers
L1 - Introduction to python Backend.pptx
Reimagine Home Health with the Power of Agentic AI​
Odoo Companies in India – Driving Business Transformation.pdf
Transform Your Business with a Software ERP System
VVF-Customer-Presentation2025-Ver1.9.pptx

Introduction to Functional programming