Refactioring
Functional Programming
What is it?
Functional programming is a programming paradigm — a style of building the structure and elements of computer programs — that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data — Wikipedia
A pure function - returns the same result if given the same arguments and It does not cause any observable side effects.
Benefits: Pure functions are stable, consistent, and predictable. The code’s easier to test.
When data is immutable, its state cannot change after it’s created. If you want to change an immutable object, you can’t. Instead, you create a new object with the new value.
If a function consistently yields the same result for the same input, it is referentially transparent.
pure functions + immutable data = referential transparency