-
-
Save ltfschoen/749a5c141fa3536a5e678757d0022c7a to your computer and use it in GitHub Desktop.
Convert elixir map to query string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule URL do | |
def to_query(input, namespace) do | |
Enum.map(input, fn({key, value}) -> parse("#{namespace}[#{key}]",value)end) | |
|> Enum.join("&") | |
end | |
def to_query(input) do | |
Enum.map(input, fn({key, value}) -> parse(key,value) end) | |
|> Enum.join("&") | |
end | |
def parse(key, value) when is_map(value) do | |
to_query(value, key) | |
end | |
def parse(key, value) do: | |
"#{key}=#{value}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment