Mind blowing Elixir

This is a simple one but my mind was blown when I first saw this line of code:

“def calculate(arr) when length(arr) <= 1 do”

I’ve never seen conditional declaration of functions before. Still haven’t gotten over how cool it is

5 Likes