Functional
Programming in a functional style often includes using functions as values by passing them in arguments, returning them from other functions, assigning them to variables for later execution, and so forth.
Adapting to that perspective requires letting go of old ideas: assignment statements, loops, classes and objects, among others. That won’t be easy.A function maps an input to an output; for the same input, it always produces the same output. That is, mathematical functions are stateless: they do not maintain any extra information or state that persists between usages of the function.
- No mutable data (no side effect).
- No state (no implicit, hidden state).
- All state is bad? No, the hidden, implicit state is bad.
- Functional programming does not eliminate state, it just makes it visible and explicit (at least when programmers want it to be).
- Functions are pure functions in the mathematical sense: their output depend only on their inputs, there is no “environment”.
- The same result returned by functions called with the same inputs.
Properties
- Pattern Matching
- Closures, a function-like construct you can store in a variable
- Iterators, a way of processing a series of elements
Links
- Rust Functional Programming
- Monad
- OCaml
- Scheme
- Rust
- C++
- ReactJS
- Haskell
- OOP
- Algebraic Data Type
- Tail Recursive
- Fold
- Abstract Type
- S Expression
- Expression-based syntax 1. Functions 2. Types 3. Higher-Order Functions (HOFs) 4. Algebraic data type 5. Pattern matching 6. Parametric polymorphism 7. Ad-hoc polymorphism through globally coherent type classes 8. Extensible records 9. Polymorphic variants 10. Exports and imports 11. Immutability by default 12. Easy syntax for mutability 13. Type inference 14. Garbage Collector 15. Records with dot-accessed fields 16. Anonymous functions