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 = |
Get Learn Functional Programming with Elixir now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.