DeepDive (Deep Dive v1.0.0) View Source

This library should serve the simple aim of finding keys in deeply nested and complex data structures used in other elixir projects. The use case for which it has been conceived was to explore the depths of the Absinthe resolution structs, but may be useful in any such case when the strutures at hand are complex and when such structures are built at runtime by some intricate logic. It is intended solely as a debugging utility, and not as a production-level tool.

Premise

To understand the logic of the exploration algorithms offered, let's point out that any nested structure we are talking about may be thought of as a tree. The nodes of the tree are either the keys in a map (or a struct), or the indices of a list. The leaves of such tree are the nodes that have no more descendants. Two nodes have the same level if they have the same number of parent nodes up to the root. A set of nodes are in the same branch if they either have the same set of parent nodes up to the root or one is ancestor of the other. In the former case, they are also at the same level.

What's inside

It currently offers two different modules that implement a different exploration strategy:

  • DeepDive.FirstFound starts a depth-first exploration and, whenever a key matches, adds it to the list of matches and drops the search on that branch.
  • DeepDive.FullWalk proceeds as the above, but does not stop on first match, rather on arriving at the leaves.

Both these strategies complete when they have explored the whole tree.

The public API is the function find_keys/2, that is present in both the aforementioned modules.

Link to this section Summary

Types

The result is what find_key gives as output. path_of_keys is the (ordered) list of keys one should use to reach the sought key. value_of_key is the value associated to such key.

Link to this section Types

Specs

result() :: [{path_of_keys :: [term()], value_of_key :: term()}]

The result is what find_key gives as output. path_of_keys is the (ordered) list of keys one should use to reach the sought key. value_of_key is the value associated to such key.