We hosted our first meetup last night, an introduction to Elixir. We had a good turn out.

Brian Stevens helped present an intro to Elixir, and helped get people wrapped around the idea of using Elixir for real world use cases.

Many of us come from the imperative, OOP world, and functional programming can take a little getting used to. We here have spent only a week on it, and have done some real work with it, but its taken a lot of getting used. One of it being the all mighty “matching” concept. Its as simple as “=” is not what you think it is, for instance

a = [:ok, “this should work fine”]

This is what you’d expect, a becomes the list [:ok, “this should work fine”]. But you can also do this:

{:ok, b} = {:ok, “this should work fine”}

still doing well here, but now b is set to “this should work fine”. But there’s the mind warp, if you do this:

{:error, b} = {:ok, “this will fail”}

you will end up with this error

** (MatchError) no match of right hand side value: {:ok, “this will fail”}

But, this is actually HUGELY valuable, when you talk about web applications, and using it for matching routes and paths. You can create some pretty cool match conditions such as this

{:ok, device} ->
 conn
 |> put_status(:created)
 |> put_resp_header(“location”, device_path(conn, :show, device))
 |> render(“show.json”, device: device)
{:error, changeset} ->
 conn
 |> put_status(:unprocessable_entity)
 |> render(BrighterlinkIo.ChangesetView, “error.json”, changeset: changeset)

I am not going get into the all powerful |> on this post, but there’s a lot of stuff you can do with this very elegant, and powerful language

Until next time, happy coding!