Functional Programming with Python

What is Functional Programming?

Programming with functions

In IP (no address), you think in terms of instructions.

It's about functions the way imperative programming is about instructions.

In FP, you think in terms of functions and what they return.

You haven't answered the question

Functional programming (like OOP) has no strict definition. It's a collection of ideas.

A philosophy, if you will.

Some programming languages - many actually - identify as Functional Languages.

Scala, Haskell, Lisp, Scheme, Clojure,
ML, OCaml, Erlang, Elm, Idris
, the list goes off.

Functional Programming

Functions are first class citizens. Meaning that everything you can do with “data” can be done with functions.

Recursion favored over loops. In some languages, there are no "loop" constructs.      I see you Haskell.

“Higher order” functions: functions that operate on functions and return functions.

Functional Programming

 

Functional programming frowns upon side effects. 

Functional programming either discourages or outright disallows statements, and instead works with the evaluation of expressions

Functional programming worries about what is to be computed rather than how it is to be computed.

Slow Fibonacci

HOW

WHAT

sum = 0
xs = [1, 4, 2, 7.8, 42]
for i in xs:
    sum += i
from operator import add
xs = [7.8, 32, 2.2]

sum = reduce(add, xs)

Code Lab

git clone https://github.com/letroot/python-fp.git

Functional Progamming with Python

By Daniel Adeyemo

Functional Progamming with Python

  • 62