SlideShare a Scribd company logo
Functional
Programming 𝝺
Kamel Ouzouigh
Highlights
● Pure Functions
● Functional Features
● ADT
● Pattern Matching
● Exception Handling
● Monads
What is Functional Programming ?
Pure functions
Immutable values
1
2
Pure function
Given the same input, will always return the same output
Doesn’t have any side effects
1
2
Pure function
// pure
Math.Max(5, 8)
"Typescript".Length
"Typescript".ToUpper()
var numbers = new List<int> { 0, 8, 9, 1 };
numbers.OrderBy(x => x)
numbers.Where(x => x % 2 == 0)
// impure
var numbers = new List<int> { 0, 8, 9, 1 };
numbers.Sort();
Action<String> greeting = name =>
{
Console.WriteLine("hi" + name + " !");
}
Benefits of pure functions
Easier to reason about
1
2
3
4
5
6
7
Easier to combine
Offer Referential Transparency
Easier to parallelize
Are Memoizable
Can be lazy
Easier to test
How about I/O ?
I/O Wrapper code
Functional features
What is a Function?
Map between values (ex: string -> int)
Methods, Lambdas, Maps
1
2
Functions are values
Full Applied Function
Partially Applied Function
Currying
Currying
Example
Pattern Matching
Algebraic Data Type(ADT)
Algebra consists of:
A set of objects
The operations that can be applied to those objects to create new objects
1
2
Examples
Numeric Algebra
Relational Algebra
Algebraic Data Type(ADT)
Algebraic Data Types are combination of other types
Algebraic Data Type(ADT)
Algebraic Data Type(ADT)
Product Type
Algebraic Data Type(ADT)
Algebraic Data Type(ADT)
Sum Type
Pattern Matching
A pattern match combines an applicability test and destructuring bind
Destructuring bind extract values from an object
Applicability test determines if the pattern matches the target
1
2
Pattern Matching
Over Composition
Pattern Matching
Over Inheritance / Closed Hierarchy
Pattern Matching
Over Inheritance / Closed Hierarchy
Pattern Matching
Over Inheritance / Closed Hierarchy
Pattern Matching
Over Inheritance / Closed Hierarchy / C#8
Handling Errors
Null Exception Problem
Alternatives to Null
How to deal with Null value ?
FP Solution
SAFETY BOX
Null Check FP Solution
Null Check FP Solution
Accessing Values
Functor
Functor
Accessing Values
Functor
Monad
Monad
flatMap aka Bind
Monad
Monad
Option aka Maybe
Option aka Maybe
Either Type
Either Type
Either Type
Either Type
Other Monads
IO
Try
State
Writer
Reader
Seq
Eval
Future

More Related Content

ODP
Functional programming
PPTX
Introduction to Functional Programming
PDF
Functional JavaScript Fundamentals
PDF
Functional Programming with Javascript
PPTX
Functional Programming in C#
PPTX
The joy of functional programming
PDF
Functional Programming for OO Programmers (part 1)
PPTX
Functional Programming in Javascript - IL Tech Talks week
Functional programming
Introduction to Functional Programming
Functional JavaScript Fundamentals
Functional Programming with Javascript
Functional Programming in C#
The joy of functional programming
Functional Programming for OO Programmers (part 1)
Functional Programming in Javascript - IL Tech Talks week

Similar to Functional Programming (20)

PPTX
WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD?
PPTX
Why Functional Programming So Hard?
PPTX
Functional programming
PDF
379008-rc217-functionalprogramming
PPTX
Intro f# functional_programming
PPTX
Functional programming in TypeScript
PDF
Introduction to Functional Programming (w/ JS)
PPTX
Why functional programming in C# & F#
PPTX
A Skeptics guide to functional style javascript
PPTX
When life gives you functions make functional programs!
PPTX
Dev Concepts: Functional Programming
PDF
Introduction to Functional Programming
PPTX
Things about Functional JavaScript
PPTX
Fuel Up JavaScript with Functional Programming
PDF
Functional programming 101
PPTX
Functional Programming in JavaScript by Luis Atencio
PDF
Functional Programming in C# and F#
PDF
Introduction to functional programming (In Arabic)
PDF
Practical functional programming in JavaScript for the non-mathematician
PPTX
Functional programming for the Advanced Beginner
WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD?
Why Functional Programming So Hard?
Functional programming
379008-rc217-functionalprogramming
Intro f# functional_programming
Functional programming in TypeScript
Introduction to Functional Programming (w/ JS)
Why functional programming in C# & F#
A Skeptics guide to functional style javascript
When life gives you functions make functional programs!
Dev Concepts: Functional Programming
Introduction to Functional Programming
Things about Functional JavaScript
Fuel Up JavaScript with Functional Programming
Functional programming 101
Functional Programming in JavaScript by Luis Atencio
Functional Programming in C# and F#
Introduction to functional programming (In Arabic)
Practical functional programming in JavaScript for the non-mathematician
Functional programming for the Advanced Beginner
Ad

Recently uploaded (20)

PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
web development for engineering and engineering
PDF
Well-logging-methods_new................
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPT
Mechanical Engineering MATERIALS Selection
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Geodesy 1.pptx...............................................
Embodied AI: Ushering in the Next Era of Intelligent Systems
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
bas. eng. economics group 4 presentation 1.pptx
web development for engineering and engineering
Well-logging-methods_new................
UNIT-1 - COAL BASED THERMAL POWER PLANTS
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Model Code of Practice - Construction Work - 21102022 .pdf
Mechanical Engineering MATERIALS Selection
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
R24 SURVEYING LAB MANUAL for civil enggi
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Geodesy 1.pptx...............................................
Ad

Functional Programming