Iptrie.filter

You're seeing just the function filter, go back to Iptrie module for more information.

Specs

filter(t(), (prefix(), any() -> boolean())) :: t()

Returns a new Iptrie, keeping only the prefix,value-pairs for which fun returns truthy.

The signature for fun is (prefix, value -> boolean), where the value is stored under prefix in the trie. Radix trees that are empty, are removed from the new Iptrie.

Example

iex> ipt = new()
...> |> put("acdc:1975::/32", "rock")
...> |> put("acdc:1976::/32", "rock")
...> |> put("abba:1975::/32", "pop")
...> |> put("abba:1976::/32", "pop")
...> |> put("1.1.1.0/24", "v4")
iex>
iex> filter(ipt, fn pfx, _value -> pfx.maxlen == 32 end)
...> |> to_list()
[{%Pfx{bits: <<1, 1, 1>>, maxlen: 32}, "v4"}]
iex>
iex> filter(ipt, fn _pfx, value -> value == "rock" end)
...> |> to_list()
...> |> Enum.map(fn {pfx, value} -> {"#{pfx}", value} end)
[
  {"acdc:1975:0:0:0:0:0:0/32", "rock"},
  {"acdc:1976:0:0:0:0:0:0/32", "rock"}
]