Pure Functions
Pure functions are functions that:
- always return the same value given the same arguments.
- do not produce side effects
Pure functions don’t do anything with anything that exists outside of their scope.
Pure functions have a lot of benefits. Whenever possible, good developers try to use pure functions instead of impure functions. Pure functions:
- Return the same result if given the same arguments. They are deterministic.
- Do not change the external state of the program. For example, they do not change any variables outside of their scope.
- Do not perform any I/O operations (like reading from disk, accessing the internet, or writing from the console).
These properties result in pure functions being easier to test, debug, and think about.
References
Next -> memoization
#declarative #computer_science #paradigm #boot_dev #programming #recursion #immutable #haskell #pure #side #fp #effect #functional