I have been working in Ruby and ROR applications for almost three years. Recently, I came across a new language, ‘Elixir’. I have started learning and playing with it a few months back.
And let me tell you guys, as per my experience, it is among one of the most fascinating and interesting languages.

Elixir is also open-source just like Ruby. There are multiple companies like BleacherReport, SquareEnix, Bet365, Pinterest, WhatsApp and many more who are using Elixir and Erlang in their live production environments.
There is so much whirring of this language in open-source communities and today markets and why should it not be?
Let’s begin our journey with our new friend Elixir. 😉
As for the beginner, I highly recommend you guys to go through Elixir’s official documentation because it is well-maintained and awesome.
What I find most fascinating about Elixir are followings assets:
- Pipe Operator
- Pattern Matching
- OTP (Open Telecom Platform)
For the sake of keeping this article short and simple, I will keep its scope limited to the discussion of the Pipe Operator only. Let’s discuss the other two features in the next articles in the series.
Pipe Operator :
In order to understand it, let’s take a simple case, where we have a list of numbers, and we want to manipulate that list by first converting each element to even number (by multiplying it by 2) and then reversing the list.
Let’s code:
Implementation in Ruby:
numbers = [1, 2, 3, 4, 5]
def list_manipulation(numbers)
numbers = numbers.map{ |x| x * 2 }
numbers.reverse
endImplementation in Elixir without Pipe Operator:
#In Elixir: without pipe operator
numbers = [10, 20, 30, 40]
def list_manipulation(numbers) do
data = Enum.map(numbers, fn x -> x * 2 end)
Enum.reverse(data)
endOn the basis of our observation, we can see the following differences between Ruby(OOP) and Elixir(Functional Programming):
- Syntax, not a major difference, it is almost the same
- In Ruby implementation, we are calling methods(map, reverse) on objects(numbers) but in Elixir code, we are passing data(numbers) to functions(map and reverse)
- In Elixir, we don’t have classes that we have in Ruby, it has modules like Enum.
- In Ruby, we are manipulating the list(numbers) but in Elixir, we are not instead we are passing the data to functions. That is due to the Immutability of data-structures in Elixir.
Implementation in Elixir using pipe operator(|>):
#In Elixir: with pipe operator
numbers = [10, 20, 30, 40]
def list_manipulation(numbers) do
numbers
|> Enum.map(fn x -> x * 2 end)
|> Enum.reverse
endAs we can see here in the above implementation, we are not passing the list of numbers to the functions which we were doing earlier. But why ??
That is because of our smart kid Pipe Operator(|>)
Pipe Operator passes data which we had received from the previous function to the next function as the first argument.
The first argument in our case is numbers. Therefore, we haven’t specified the first argument in the map and reverse functions of the Enum module.
As a result pipe operator makes it easy to read and understand the data transformations and chaining between different functions(map and reverse in our case). We don’t have to explicitly save the return value of a function to the local variable to just pass it to the next function.
At the end of the day, the pipe operator provides us the flexibility to write clean code and avoid messy programming.
So, here we have learned about pipe operator, let’s continue more Elixir’s assets — Pattern matching and OTP in the next blogs.
Hope you liked it. For more such information stay tuned … 😁
Happy Coding.
