From 7c76f61997723b64f94a590d9870dd5bd5b3a2c2 Mon Sep 17 00:00:00 2001 From: Brad Hanks Date: Sun, 15 Dec 2024 20:12:59 -0700 Subject: [PATCH] functions refactored to map_reduce (#423) * map_reduce * Apply suggestions from code review --------- Co-authored-by: Vince Foley <39946+binaryseed@users.noreply.github.com> --- lib/new_relic/sampler/beam.ex | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/new_relic/sampler/beam.ex b/lib/new_relic/sampler/beam.ex index 528124a..487874a 100644 --- a/lib/new_relic/sampler/beam.ex +++ b/lib/new_relic/sampler/beam.ex @@ -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