Skip to content

Commit

Permalink
functions refactored to map_reduce (#423)
Browse files Browse the repository at this point in the history
* map_reduce

* Apply suggestions from code review

---------

Co-authored-by: Vince Foley <[email protected]>
  • Loading branch information
bradhanks and binaryseed authored Dec 16, 2024
1 parent 6eae916 commit 7c76f61
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/new_relic/sampler/beam.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ defmodule NewRelic.Sampler.Beam do
end

defp delta(:util, previous, current) do
{active, total} =
{_, {active, total}} =
Enum.zip(previous, current)
|> Enum.map(fn {{n, a0, t0}, {n, a1, t1}} -> {n, a1 - a0, t1 - t0} end)
|> Enum.reduce({0, 0}, fn {_n, d_a, d_t}, {acc_a, acc_t} -> {acc_a + d_a, acc_t + d_t} end)
|> Enum.map_reduce({0, 0}, fn
{{n, a0, t0}, {n, a1, t1}}, {acc_a, acc_t} ->
{{n, a1 - a0, t1 - t0}, {acc_a + (a1 - a0), acc_t + (t1 - t0)}}
end)

safe_div(active, total)
end
Expand Down

0 comments on commit 7c76f61

Please sign in to comment.