What does the Circumflex / Pin / Cap (^) operator do in Elixir?

I was looking at the Ecto documentation when I hit the interpolation part, where Ecto uses the Circumflex (^) sign, for example.

def with_minimum(age, height_ft) do from u in User, where: u.age > ^age and u.height > ^(height_ft * 3.28) end 

Made me wonder what he does? :-)

+5
source share
1 answer

Elixir uses the pin operator to match the pattern to match the current value of the variable. You can read more about this here: http://elixir-lang.org/getting-started/pattern-matching.html

Ecto changes the pin operator to mean query interpolation, where you pass the Elixir value to the query. You can argue that their behavior is somewhat similar to the fact that the database efficiently executes a query, trying to find a value that matches, but the easiest way is to think that this is really query interpolation. More details here: http://hexdocs.pm/ecto/Ecto.Query.html

+3
source

All Articles