Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do these operators mean in Elixir? ~>>, <<~

What do these operators mean in Elixir? ~>>, <<~

They are listed here http://elixir-lang.org/getting-started/basic-operators.html

I get the following error:

iex(28)> b=1
1
iex(29)> b~>>1
** (CompileError) iex:29: undefined function ~>>/2
like image 972
Charles Okwuagwu Avatar asked Nov 12 '15 10:11

Charles Okwuagwu


1 Answers

There are some operators that currently have no meaning, but you can use them in macros you define or just define them as functions. For example:

defmodule Operators do
  def a ~>> b do
    a + b
  end
end

defmodule Test do
  def test do
    import Operators

    1 ~>> 2
  end
end

IO.inspect(Test.test) # => 3

The general idea is that Elixir wants to avoid operator proliferation (think libraries that define dozens of new operators) so when defining your macros you need to use the ones that are already there.

like image 101
Paweł Obrok Avatar answered Sep 27 '22 15:09

Paweł Obrok