dot-notes v1.0.0 DotNotes.Reduce

Reduction module for a haystack, allowing the developer to iterate both keys and nests inside a haystack and keep state in an accumulator whilst doing so.

DotNotes.recurse/3 is powered by this module under the hood, however the existence of DotNotes.reduce/4 is a deviation from the interfaces defined in other dot-notes libraries. This is because accumulation is the only good way to keep track of states in Elixir, and so it’s only natural to provide it.

Summary

Functions

Carries out a reduction over a haystack

Types

haystack :: %{} | []

Functions

execute(haystack, acc, handler, prefix \\ "")

Specs

execute(haystack, accumulator :: any, handler :: function, prefix :: binary) :: accumulator :: any

Carries out a reduction over a haystack.

This operates by retrieving a list of keys at each level, iterating through them and then nesting into any new levels found. All keys and values are fed through to the handler function.

If desired, the entire path of the current key can also be passed by adding a third parameter to the callback. Finally, a fourth parameter of an accumulator can be used to maintain state. This is set to :dn_disabled if there’s no need to keep track of state.