laboshinl
Flow group_by() result differs from Enum.group_by
Hi all,
Could please someone explain me why am I getting incorrect result with Flow.group_by()
Marked As Solved
lackac
You need to call partition/2 before group_by/3. The usual purpose of partitioning before a reduce operation is to ensure that events that belong together are handled by the same process. This is important to know when using group_by/3 since you want to group. The examples in the Flow docs deal with this in detail.
In your case what is probably missing is choosing the right key to partition by. Take a look at the docs of partition/2. You will need something like:
|> Flow.partition(key: &elem(&1, 1).proto)
Also Liked
NobbZ
Because you have neither told us what your code looks like, nor what incorrect results you get and what makes them incorrect in your opinion.
I tend to say, that the result is correct but your assumption does not match your
shanesveller
I would try including Flow.reduce/3 after a partition:
File.stream!("path/to/some/file")
|> Flow.from_enumerable()
|> Flow.flat_map(&String.split(&1, " "))
|> Flow.partition()
|> Flow.reduce(fn -> %{} end, fn word, acc ->
Map.update(acc, word, 1, & &1 + 1)
end)
|> Enum.to_list()
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









