All posts

Elixir ternary operator


If you’re coming into elixir from a language like Javascript or Ruby you are familiar with ternary expressions and how to use them to simplify conditionals. In practice they look something like this:

const val = condition ? truthy_handler : falsy_handler

In elixir it is handled differently, the most common and frequently used way being:

if(condition, do: truthy_handler, else: falsy_handler)

If you like conditions, you might also enjoy the post Get the index position from element in a matched condition.


I built two products to help fund continued efforts for this website, it would mean a lot if you would check them out:
1. 2500+ Words for the Undermotivated Software Engineer - A short essay I wrote on the titled topic ($3).
2. Build 3 Chrome Extensions in Under 2 Hours - A course I built to teach chrome extension development ($9-20).