tajihiro
How to use Enum.group_by with multi columns
I know how to use Enum.group_by with one column, but I’m not sure how to use it with multi columns.
Following example is group_by(id).
input = %{
"1" => [
%{id: "1", seq: "1", lang: "Elixir", name: "Bob"},
%{id: "1", seq: "1", lang: "Java", name: "Bob"},
%{id: "1", seq: "2", lang: "Ruby", name: "Bob"}
],
"2" => [
%{id: "2", seq: "1", lang: "Elixir", name: "Tom"},
%{id: "2", seq: "2", lang: "C#", name: "Tom"}
],
"3" => [
%{id: "3", seq: "1", lang: "Python", name: "Dave"},
%{id: "3", seq: "1", lang: "Java", name: "Dave"},
%{id: "3", seq: "2", lang: "Ruby", name: "Dave"}
],
"4" => [%{id: "4", seq: "1", lang: "Python", name: "Jane"}]
}
I would like to make group_by with id & seq, in this case.
Is there any idea for it?
Marked As Solved
josevalim
Creator of Elixir
You can do: Enum.group_by(collection, &{&1.id, &1.seq})
6
Also Liked
tajihiro
Thank you so much. It worked as I expected.
2
Popular in Questions
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir?
...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> somethi...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Other popular topics
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Hello, how can I check the Phoenix version ?
Thanks !
New
What learn first? Rust or Elixir
Hi Elixir community!
I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New









