Find and delete maps with condtion

I have this maps

  "6f833e1f-be73-4089-91d2-5995e2ec4770": %{"time" => "1544976648"},
  "edda2172-d938-440f-a6a2-22c0b3906150": %{"time" => "1544977248"},
  "edda2172-d938-433f-a6a2-22c0b1006900": %{"time" => "1544978248"},
  "edda2172-d938-100f-a6a2-22c0b20069f4": %{"time" => "1544979248"}

and I want to delete maps that their time are 10 min past from current time
how can do this in best way ?

sorry for my bad english

That map can’t exist, as it has 3 keys that are the same.

Aside if that, just get the current timestamp and substract 600 seconds, then compare lesser or equal than in a filter.

1 Like

What you show is a single overall map, but we can work with each key/value in it to remove keys whose value has a time older than 10 minutes.

ten_min_ago = :erlang.system_time(:second) - 10 * 60
|> Enum.reject(fn {_k, %{"time" => time_str}} -> String.to_integer(time_str) < ten_min_ago end)

sorry . I was correcting the wrong