SlideShare a Scribd company logo
Becoming a
Functional
Programmer Presented By : Harit Himanshu
2
Agenda
About Harit
Goal of the talk
Pre-requisites
Topics
Next Steps
Final Thoughts
3
About Me
harittweets
Software Consultant
Favorites Work Product Trave
l
moneybonsai.com
4
Goal
Vocabulary and Concepts
Scala JavaScript
Elm Haskell
OCaml Java
Languages
5
Pre-requisites
Language Personal Finance
Functions
Variables
Income
Taxes
Expenses
6
ImmutabilityPure and Impure Functions
Expressions and
Statements
Topics
Functions
7
CurryingRecursion
Higher-Order Functions
Topics (contd.)
Referential
Transparency Concurrency
8
Function
X Y
Time Money
9
Types of Functions
Pure Impure
Pure function is a function where the return
value is only determined by its input values,
without observable side effects
11
def grossMonthlySavings(grossMonthlyIncome: Double, expenses: Double) =
grossMonthlyIncome - expenses
grossMonthlySavings(10000.0, 4000.0) // 6000.0
grossMonthlySavings(10000.0, 4000.0) // 6000.0
grossMonthlySavings(10000.0, 4000.0) // 6000.0
12
Impure Function Examples
API
Calls
Read/Write
to
Databases
13
Pure vs Impure Functions
Pure Impure
14
Pure and Impure Functions
Pure
Impure
15
Pure Function Benefits
Easy to Test Reusable Parallelizable
An expression is something that yields a value
17
val savings = income - expenses
Expression Example
Statement is some code that does some action
19
def printUserName(userId: Int, name: String) = {
println(s"The user[$userId] is called as $name")
}
Statement Example
Immutability
21
i = 10
j = 20
k = i + j // 25
Mathematics
22
i = 10
j = 20
k = i + j // 30
i = 100
j = 90
k = i - j // 10
Imperative Programming
23
Why Care About Immutability?
Easier to Reason No accidental changes Parallelizable
24
Immutability in Real World?
Bank Transaction
25
Variables in Scala
var expenses = 4000.0
expenses = 5000.0
val income = 10000.0
// compilation error
income = 9000.0
var (Mutable) val (Immutable)
26
Mutability in var References
Amazon
Salaryt2
t1
27
Mutability in var References
Amazon
Salaryt2
t1
28
Immutability in val References
Amazon
Salaryt2
t1
29
Immutable Reference Mutable Memory
Amazont1
An expression is (said to be) referentially
transparent if it can be replaced with its value
without changing the program’s behavior.
Recursion
32
Recursion Properties
Base
Case
Recurse
To
Reduce
33
Iteration Recursion
Iteration vs Recursion
Tail recursion is a technique where the
calculations are completed first, before passing
in the results to the next recursive call
Higher-Order Functions are functions that
take other functions as input or return functions
as the result
36
def getFoodExpenses(ts: List[Transaction]): Double = {
val amounts = for (i <- ts.indices if ts(i).category == Food) yield ts(i).amount
amounts.sum
}
Creating Higher-Order Function
(Transaction) => BooleanTransaction => Boolean
37
def getFoodExpenses(ts: List[Transaction], pred: Transaction => Boolean): Double = {
// Implementation goes here
}
Creating Higher-Order Function
val amounts = for (i <- ts.indices if pred(ts(i))) yield ts(i).amount
amounts.sum
Express what needs to happen instead of how
39
Map is a Transformation
val amounts: List[Double] = transactions.map((t: Transaction) => t.amount)
List.map => List
Set.map => Set
40
Filter is a Projection
val filtered: List[Transaction] = transactions.filter((t: Transaction) => t.debit == true)
41
Opening a Bank Account
42
Opening another Bank Account
Document Collection Counter Cash Counter
Currying is when a function that takes multiple
arguments is divided into a series of functions
that take part of the arguments
Concurrency
45
Low-Level Concurrency
Threads Locks Synchronization
46
Computing in Future
val resultInFuture: Future[Double] = Future {
// some asynchronous computation returning Double
}
47
Next Steps
48
Programming in Scala, 3rd
Edition
49
https://www.pluralsight.com/courses/scala-big-picture
Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)
51
Thank You
harittweets

More Related Content

PPT
Operators in C++
PPT
C++ functions presentation by DHEERAJ KATARIA
DOCX
18 dec pointers and scope resolution operator
PPT
Functions in C++
PPT
operators and expressions in c++
PPTX
Functions in C++ (OOP)
DOCX
C – operators and expressions
PPTX
Recursion in c++
Operators in C++
C++ functions presentation by DHEERAJ KATARIA
18 dec pointers and scope resolution operator
Functions in C++
operators and expressions in c++
Functions in C++ (OOP)
C – operators and expressions
Recursion in c++

What's hot (20)

PPTX
Increment and Decrement operators in C++
PPTX
Operators and expressions in C++
PPSX
Functions in c
PPTX
Functions in C
PPT
Operators in C Programming
PPTX
Operators in C & C++ Language
PPTX
Learning C++ - Functions in C++ 3
PPT
C++ Functions
PDF
Programming Fundamentals Decisions
PPTX
c++ programming Unit 4 operators
PPT
C++ functions
PPT
C++ functions
PPTX
Function BPK2
PPTX
C and C++ functions
ODP
Function
PPTX
Call by value
PPT
FUNCTIONS IN c++ PPT
PPT
Basic c operators
PPT
Operator & Expression in c++
PPTX
Function class in c++
Increment and Decrement operators in C++
Operators and expressions in C++
Functions in c
Functions in C
Operators in C Programming
Operators in C & C++ Language
Learning C++ - Functions in C++ 3
C++ Functions
Programming Fundamentals Decisions
c++ programming Unit 4 operators
C++ functions
C++ functions
Function BPK2
C and C++ functions
Function
Call by value
FUNCTIONS IN c++ PPT
Basic c operators
Operator & Expression in c++
Function class in c++
Ad

Similar to Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions) (20)

PPTX
Python Lecture 4
PDF
Functional programming 101
PPTX
UNIT – 3.pptx for first year engineering
PPTX
Fuel Up JavaScript with Functional Programming
PDF
Lecture 8.pdf
PPTX
Introduction To Programming with Python-1
PPT
C++ functions
PDF
Functional Objects in Ruby: new horizons – Valentine Ostakh
PPTX
Functional programming
PPTX
Python advance
PDF
Functional Programming in C#
PPT
Functions and pointers_unit_4
PPT
Functions in c++
PDF
Functions in Pythons UDF and Functions Concepts
PDF
Python Unit 3 - Control Flow and Functions
PPT
Ch4 functions
PPTX
Understanding Python Programming Language -Functions
PPTX
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
PPTX
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
PDF
PythonStudyMaterialSTudyMaterial.pdf
Python Lecture 4
Functional programming 101
UNIT – 3.pptx for first year engineering
Fuel Up JavaScript with Functional Programming
Lecture 8.pdf
Introduction To Programming with Python-1
C++ functions
Functional Objects in Ruby: new horizons – Valentine Ostakh
Functional programming
Python advance
Functional Programming in C#
Functions and pointers_unit_4
Functions in c++
Functions in Pythons UDF and Functions Concepts
Python Unit 3 - Control Flow and Functions
Ch4 functions
Understanding Python Programming Language -Functions
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
PythonStudyMaterialSTudyMaterial.pdf
Ad

More from Tech Triveni (20)

PDF
UI Dev in Big data world using open source
PDF
Why should a Java programmer shifts towards Functional Programming Paradigm
PDF
Reactive - Is it really a Magic Pill?
PDF
Let’s go reactive with JAVA
PDF
Tackling Asynchrony with Kotlin Coroutines
PDF
Programmatic Ad Tracking: Let the power of Reactive Microservices do talking
PDF
Let's refine your Scala Code
PDF
Supercharged imperative programming with Haskell and Functional Programming
PDF
Observability at scale with Neural Networks: A more proactive approach
PDF
Semi-Supervised Insight Generation from Petabyte Scale Text Data
PDF
Finding the best solution for Image Processing
PDF
Proximity Targeting at Scale using Big Data Platforms
PDF
Effecting Pure Change - How anything ever gets done in functional programming...
PDF
Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...
PDF
Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)
PDF
Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...
PDF
UX in Big Data Analytics - Paramjit Jolly (Guavus)
PDF
Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)
PDF
Micro Frontends Architecture - Jitendra kumawat (Guavus)
PDF
Apache CarbonData+Spark to realize data convergence and Unified high performa...
UI Dev in Big data world using open source
Why should a Java programmer shifts towards Functional Programming Paradigm
Reactive - Is it really a Magic Pill?
Let’s go reactive with JAVA
Tackling Asynchrony with Kotlin Coroutines
Programmatic Ad Tracking: Let the power of Reactive Microservices do talking
Let's refine your Scala Code
Supercharged imperative programming with Haskell and Functional Programming
Observability at scale with Neural Networks: A more proactive approach
Semi-Supervised Insight Generation from Petabyte Scale Text Data
Finding the best solution for Image Processing
Proximity Targeting at Scale using Big Data Platforms
Effecting Pure Change - How anything ever gets done in functional programming...
Live coding session on AI / ML using Google Tensorflow (Python) - Tanmoy Deb ...
Distributing the SMACK stack - Kubernetes VS DCOS - Sahil Sawhney (Knoldus Inc.)
Blue Pill / Red Pill : The Matrix of thousands of data streams - Himanshu Gup...
UX in Big Data Analytics - Paramjit Jolly (Guavus)
Simplified Scala Monads And Transformation - Harmeet Singh (Knoldus Inc.)
Micro Frontends Architecture - Jitendra kumawat (Guavus)
Apache CarbonData+Spark to realize data convergence and Unified high performa...

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
cuic standard and advanced reporting.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectroscopy.pptx food analysis technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Network Security Unit 5.pdf for BCA BBA.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Digital-Transformation-Roadmap-for-Companies.pptx
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
cuic standard and advanced reporting.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
The AUB Centre for AI in Media Proposal.docx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

Becoming a Functional Programmer - Harit Himanshu (Nomis Solutions)