Skip to Main Content
Mastering Elixir
book

Mastering Elixir

by André Albuquerque, Daniel Caixinha
July 2018
Intermediate to advanced content levelIntermediate to advanced
574 pages
14h 7m
English
Packt Publishing
Content preview from Mastering Elixir

Disk-usage rank query

In the previous section, we ended up getting the number of files per user. We will now iterate on the previous result to create a disk-usage ranking. Since we want the disk usage, we will have to update the previous files_by_user_v3 flow so that it accumulates each file size per user id as well:

$ cat examples/search.exsimport_file("./examples/sample_data.exs")# ...disk_usage_by_user = media_set            |> Flow.from_enumerable(max_demand: 1)            |> Flow.partition(key: {:key, :user_id})            |> Flow.reduce(fn -> %{} end,            fn %{user_id: user_id, file_size: size}, accum ->            Map.update(accum, user_id, size, &(&1 + size))            end)

The previous disk_usage_by_user flow gives us the expected results, showing each user's disk usage. User 3 is clearly ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Testing Elixir

Testing Elixir

Andrea Leopardi, Jeffrey Matthias

Publisher Resources

ISBN: 9781788472678Supplemental Content