“if” statement can return value | Elixir / Phoenix

Photo by Nick Karvounis on Unsplash

I’m not trying to use “if” statement in Elixir as I’ve already mentioned it in the first post. But ….the reality is different. We can avoid “if” completely from codes we will write. I think it is so great, but, on the other hand, this will sometime make our codes not be readable. So, I unwillingly use “if” statement like the following.

It’s so weird for me. Even I have no choice but to use “if”, I want to find another way of writing. Yes, I can write it by one line.

O.K…. I have been writing by this way for the first 2 months with some patience…

You know what? Elixir is not the OOP language! Because of my OOP experience of more than 10 years, I could not imagine talking more about it with Elixir.

Actually, the condition syntax in Elixir can returns value!
So, now I’m writing above code like this!

--

--