Functional Programming Basics
Big Data Analytics with Python, AIMS-Rwanda 2023
Dunstan Matekenya, PhD
Contents
Advice on Tackling a Big Data Problem
Some questions to ask yourself before you jump to the big guns
Big Data Package Ecosystem in Python
There are only 4 packages which are known to handle large datasets in Python. Out of those, Pyspark and Dask are the most stable options for enterprise level data processing
Explore Dask on Your Own
In this course, we use Pyspark but I encourage you to explore Dask
What is Functional Programming?
“In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program.”
Wikipedia
A pure function is a function whose output value follows solely from its input values and cannot be affected by any mutable state or other side effects. In functional programming, a program consists entirely of evaluation of pure functions.
What is Functional Programming
Functional programming style in Scala
Procedural programming style in Python
Traditional Vs. Functional Program in Javascript
Source: Wikipedia
Advantages of Functional Programming
Disadvantages of Functional Programming
Advantages of Functional Programming-Parallelization
Input
Function
Output
Increase compute nodes as input size increase
Compute node-1
Compute node-2
Lambda Functions
Source: Wikipedia
Data types such as numbers, strings, booleans etc. don’t need to be bound to a variable. The same can be done for functions!
Lambda Functions in Scala vs. Python
Functional Programming and Big Data processing
Functional Programming in Python
Data Structures for Functional Programming in Python
Why Does Data Immutability Matter in FP
Defining Lambda Functions in Python
How Lambda Functions Fit Together with Python Function Definition and Lambda Calculus
Higher Order Functions
A function is a higher-order function if it either takes in one or more functions as parameters and/or returns a function.
Higher Order Functions in Action
Common Higher Order Functions
Similar idea to the map and reduce functions in MapReduce programming model
Map Example
Reduce Example
Further Reading in Functional Programming
Now, we already for a tutorial on Functional Programming in Python