Today I am going to talk about how to design Pure Function and help you understand the benefits of pure function.
Nowadays Functional Programming is getting a lot of attention due to the advantages it offers like parallelism, easier testing, _predictability _ and many others.
Pure functions is a concept mainly used in functional programming languages but it can be applied in any programming paradigm
Definition
Pure functions can be defined as
- The function always returns the same value for the same inputs. The output is only determined by its input values.
- A function where the return value is only determined by its input values, without observable side effects
Characteristics Of Pure Function
- Function should always return a result.
- Function must only depend on their inputs. That means this function should not use any other value than the function inputs to calculate the result
- Pure functions cannot have other side effects than the computation of its return value.
- Referentially transparent: An expression is said to be referentially transparent if
- it can be replaced with its corresponding value without changing the
- program’s behaviour.
#functional-programming #lambda-function #functor #kotlin #programming #functional-components #coding #coding-skills