Hi
i want to concat all the keys, from a map into one string separatly by comma, i was doing this:
> names = claims
> |> Map.keys
> |> Enum.each(fn (x)-> names <> x end)
Hi
i want to concat all the keys, from a map into one string separatly by comma, i was doing this:
> names = claims
> |> Map.keys
> |> Enum.each(fn (x)-> names <> x end)
Rather than Enum.each
, you will want to use Enum.join
.
Example:
data = %{"foo" => 1, "bar" => 2, "baz" => 0}
data |> Map.keys |> Enum.join(",")
For more general iterations where you are accumulating results, using Enum.each
is usually not what you want, but instead, Enum.reduce
.
Just a quick note about Enum.each
. Its really only used for working with code that has side effects. It always returns :ok
, not anything from the result of the passed fn.