by sterwill · 7y ago · 0 comments
Other programming languages let you return from any line in the function, no matter how deep in a conditional, inside nested loops, before or after variable side effects, etc. Tricky to know just _what_ that function will do given some inputs.
def transform_data(raw_data) when length(raw_data) == 1, do: []
def transform_data(raw_data) do
# actual function code goes here
end
That said, I wouldn't want to see the above snippet in my team's codebase :) def transform_data([_|[]]) do: []
I just wanted an example of using guard clauses. It does depend on the actual code though, there's probably a more elixiry solution.