Assertive Code
https://dashbit.co/blog/writing-assertive-code-with-elixir
BAD
def get_token(string) do
parts = String.split(string, "&")
Enum.find_value(parts, fn pair ->
key_value = String.split(pair, "=")
Enum.at(key_value, 0) == "token" && Enum.at(key_value, 1)
end)
end
Using pattern matching is good way to get assertive code
Good
def get_token(string) do
parts = String.split(string, "&")
Enum.find_value(parts, fn pair ->
[key, value] = String.split(pair, "=")
key == "token" && value
end)
end