Functional Programming 👷🏼♂️👷🏼♀️
Overview
First Class Functions
- functions can be used as inputs and outputs of other functions
- functions can be assigned to variables and can be stored in collections
- can perform all the operations on functions that you can do with values of other types
Higher-Order Funcions
- takes other functions as arguments, or returns them as results
Avoiding state mutation
- once created an object never changes
Pure functions
- no side effects (no memory external to function is modified, no I/O, no exceptions thrown)
- when called with same values will always return the same result
Closure
- a function passed around along with it's environment
Currying
- evaluating multiple arguments of a function, one by one, producing intermediate results
f(x,y) = x + y
f(3,4) = 3 + 4
substituting for x we get
f(3, y) = 3 + y
Define g(y) as g(y) = 3 + y then following is true:
f(3,y) = g(y) = 3 + y