Functional Programming
What is functional programming?
Functional programming is a programming paradigm where programs are constructed by applying and composing functions. Functions are treated as first-class citizens, meaning that they can be bound to names (including local identifiers), passed as arguments, and returned from other functions, just as any other data type can.
- In normal coding pattern
// 2 * 3 - 4
int a = 1 + 2;
int b = a * 3;
int ans = b - 4;
- In functional programming
// 2 * 3 - 4
int ans = subtract(multiply(add(1,2), 3), 4);
//another version
int ans = add(1,2).multiply(3).subtract(4);
The advantages
- Code is neat
- Easy to read and understand
- For parallel