Software EngineeringFunctional Programming (FP)
Functional Programming
Cheat sheet for Functional Programming
Functional Programming
Functional Programming concepts focus on programming using Pure Functions and avoiding Shared State or Mutable Data.
Pure Functions
Pure Functions are functions with the following properties:
- Always produce the same Output when given the same Input (Deterministic).
- Have no Side Effects or modifications to State outside the function.
Immutability
Immutability means that Data cannot be modified after it is created. If Data needs to be changed, new Data must be created instead of modifying the existing Data.
Higher-Order Functions
Higher-Order Functions are functions that can accept other functions as Arguments or return an Output as a function. This helps in Function Composition and creating highly flexible Abstractions.
Declarative vs Imperative
- Declarative: Writing code that describes what the desired outcome is (What to do), such as using
map,filter, orreduce. - Imperative: Writing code that specifies detailed execution steps (How to do), such as using a
forloop to change State variables.