Skip to content

Latest commit

 

History

History
24 lines (16 loc) · 1.18 KB

301-09.md

File metadata and controls

24 lines (16 loc) · 1.18 KB

Home

Refactioring
Functional Programming

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

Pure Function

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.

Immutability

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.

Referential Transparency

If a function consistently yields the same result for the same input, it is referentially transparent.

pure functions + immutable data = referential transparency