TL;DR
In the previous post, we presented I/O Lists, the data type for creating data streams for IO devices. Today we move on Elixir operators, where many of them are Elixir Functions. This post is part of the functional language series, and it is based on the remarkable book Elixir In Action by Sasa Juric.
Operators Are Functions
An elixir Kernel module is the home of many operators as Kernel Functions. This way, core Elixir features are minimal and make Elixir easy and cheap to maintain.
In the above image, you can see logical, short circuit, and mathematical operators. Let’s explore operator -
. Note that we have two functions for that operator, with one and two parameters:
@spec
is for describing function input/output parameters, and it is used by dialyzer
a tool that helps you catch bugs before runtime. guard
Defines could this function be used in the function guard clause. You also have a simple example of how to use this operator.
Remember
One of the important Elixir features is that most operators are Kernel functions. Kernel functions are available by default.