CastLouis

CastLouis

Map.keys convert to string

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)

Most Liked

Qqwy

Qqwy

TypeCheck Core Team

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.

smpallen99

smpallen99

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.

Where Next?

Popular in Discussions Top

chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
chuck
Let me start by stating an assumption: Phoenix is a great approach to building REST APIs. There are many reasons for this, but I will ass...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
eteeselink
Hi all, In the last days, two things happened: A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New
matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement