Building Programs with Functions
In functional programming, functions are the primary tools for building a program. You can’t create a useful program without writing or using functions. They receive data, complete some operation, and return a value. They are usually short and expressive.
We combine multiple little functions to create a larger program. The complexity of building a larger application is reduced when the functions have these properties:
- The values are immutable.
- The function’s result is affected only by the function’s arguments.
- The function doesn’t generate effects beyond the value it returns.
Functions that have these properties are called pure functions. A simple example is a function that adds 2 to a given number:
|||add2 = |