Elixir implementation of Huet's zippers.
// momentum
// why it's here
- Active: last commit today
- Around since 2017 and still shipping
// how to help
// readme
ExZipper
An Elixir implementation of [Huetβs Zipper][huet], with gratitude to Rich Hickeyβs [Clojure implementation][clojure].
Installation
@deps [
ex_zipper: "~> 1.0"
]
Usage
Below is an outline of the API provided by ExZipper.Zipper. See the full
documentation here for usage examples
Creating zippers
ExZipper.Zipper provides one zipper construction function for working with plain lists,
ExZipper.Zipper.list_zipper/1
iex> Zipper.list_zipper([1,[],2,[3,[4,5]]])
For other tree shapes, define a module that implements the ExZipper.Tree
behaviour and pass it, along with your root data structure, to
ExZipper.Zipper.new/2. The behaviour has three callbacks:
branch?/1returns whether a node is a branch (a node that can have children, even if it currently has none)children/1returns the children of a branch node, in ordermake_node/2returns a new node built from an existing node and a new list of children. For any branchnode,children(make_node(node, kids))must equalkids, or edits made through the zipper will be lost when the tree is rebuilt