In Elixir, Many Operators Are Functions — Tentamen Software Testing Blog

Image for post
Image for post
Elixir Operators As Kernel Functions

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:

Image for post
Image for post
Documentation For Elixir + Operator

@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.

Originally published at https://blog.tentamen.eu on October 21, 2020.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store