Skip to content

Instantly share code, notes, and snippets.

@ihorkatkov
Created March 19, 2018 17:49
Show Gist options
  • Save ihorkatkov/d0913fbeb42be37e406da534199286cc to your computer and use it in GitHub Desktop.
Save ihorkatkov/d0913fbeb42be37e406da534199286cc to your computer and use it in GitHub Desktop.
defmodule Example do
defp plug_address_chunk(addr, nil), do: addr
defp plug_address_chunk(addr, key), when String.length(addr) > 0 and String.length(key) > 0 do: addr <> ", " <> city
defp plug_address_chunk(addr, key), do: addr <> city
def get_address() do
street = …
city = …
state = …
zip = …
addr = street || ""
result = addr
|> plug_address_chunk(city)
|> plug_address_chunk(state)
|> plug_address_chunk(zip)
case result do
"" -> "Unknown Location"
address -> address
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment