Elixir from a NodeJs Developer’s Perspective — Part I

Hasan Tayyar Beşik
2 min readSep 20, 2021

I’ve decided to start learning and using Elixir.

My current playlist to getting started contains some books and videos:

I will take notes and maybe share part by part.

Here are the first batch of notes

Notes taken during first Elixir session

  • iex — the Elixir interactive shell is fast (considering that I was using NodeJs for long time anything is fast)
  • https://elixircasts.io/ — perfect free getting started screen casts

Module and functions

  • There are private and public functions: defined via def and defp.
  • Erlang functions, of course, can be used in Elixir.
  • Reloading a module done via an internal function named r
  • Functions can take guard clauses to be used for anything but most helpfully to avoid returning unwanted values like via checking the arguments
  • Same function name can be defined like java method overloading.
  • Anonymous functions are possible (kind of arrow function in JS terms) but anonymous functions are called differently. with an extra dot before the parentheses. this improves the readability
function overloading
  • Anonymous functions can be created using & as following. The other ampersands are to define the parameters. &1 is the first &2 is the second ... argument.
An anonymous function defined via an arrow and called with an extra dot.
  • Inside an anonymous function we can call a function by appending the arguments to the given function.
An anonymous function is defined by using `&` and called. Another function is passed inside an anonymous function. /2 is the number of arguments to be passed to the function inside.
  • The same argument passing can be used for lists and tuples like. See the next image.
List and tuples taking arguments like anonymous functions.

Anonymous functions concept or this entire functional concept is nothing new to a Js developer who has been adopted functional development in Js. But Elixir and JS is fundamentally different. Elixir is concurrent and Js is async.

--

--

Hasan Tayyar Beşik

GCloud, AWS, Security, NodeJs, Berlin — This blog is mostly technical and multilingual. Be aware of possible and multiple typos!