The main zipper module.
Every member is importable under the package. I.e. import { makeZipper, value } from 'zippa'
Makes a Zipper factory that uses the implementation provided in the parameters.
(Function)
Function with signature
(item: T) => boolean
that indicates if the item can have children.
(Function)
Function with signature
(item: T) => Array<T>
that returns an array of children for a branch.
(Function)
Function with signature
(item: T, children: Array<T>) => T
that returns a new item, given an old item and it's new children.
Function
:
zipper factory with signature
(item: T) => Zipper
. The factory
can also be accessed from the factory's
from
property.
Gets the value of the current location.
(Zipper)
(T | null)
:
Moves location to the root, constructing any changes made.
(Zipper)
Zipper
:
Moves location to the parent, constructing a new parent if the children have changed.
If already at the top, returns null.
(Zipper)
(Zipper | null)
:
Moves location to the leftmost child. If the current item is a leaf, returns null.
(Zipper)
(Zipper | null)
:
Moves location to the left sibling. If the current location is already the leftmost, returns null.
(Zipper)
(Zipper | null)
:
Moves location to the right sibling. If the current location is already the rightmost, returns null.
(Zipper)
(Zipper | null)
:
Moves location to the leftmost sibling. If the current location is already the leftmost, returns itself.
(Zipper)
Zipper
:
Moves location to the rightmost sibling. If the current location is already the rightmost, returns itself.
(Zipper)
Zipper
:
Moves location to the next element in depth-first order.
(Zipper)
Zipper
:
Moves location to the previous element in depth-first order.
(Zipper)
Zipper
:
Returns a boolean indicating if the zipper has been
exhausted by calls to next
.
(Zipper)
boolean
:
Returns a boolean indicating if the zipper is at the top.
(Zipper)
boolean
:
Returns a boolean indicating if the zipper is not at the top.
(Zipper)
boolean
:
Returns a boolean indicating if the current location is not a leaf.
(Zipper)
boolean
:
Returns a boolean indicating if the current location is a leaf.
(Zipper)
boolean
:
Returns a boolean indicating if the item at the current location is the leftmost sibling.
(Zipper)
boolean
:
Returns a boolean indicating if the item at the current location is the rightmost sibling.
(Zipper)
boolean
:
Returns a boolean indicating if the zipper is not at the top.
Alias for isNotTop
(Zipper)
boolean
:
Returns a boolean indicating if the item at the current location is the leftmost sibling.
Alias for isLeftmost
(Zipper)
boolean
:
Returns a boolean indicating if the item at the current location is the rightmost sibling.
Alias for isRightmost
(Zipper)
boolean
:
Alias for isBranch
(Zipper)
(Any)
boolean
:
Replaces the current item with the given value.
(T)
item to replace the current one with.
(Zipper)
Zipper
:
Replaces the current item with value returned
by calling fn
with the current item.
Zipper
:
Inserts a new item as the left sibling.
(T)
(Zipper)
Zipper
:
Inserts a new item as the right sibling.
(T)
(Zipper)
Zipper
:
Inserts a new item as the leftmost child.
(T)
(Zipper)
Zipper
:
Inserts a new item as the rightmost child.
(T)
Zipper
:
Removes item at the current location. Returns location that would be previous in depth first search.
(Zipper)
Zipper
:
The Zipper class.
Keeps track of the current item, path, and metadata (implementation functions).
Don't use this constructor directly. Create your own Zipper factory with makeZipper
,
and use it to create instances of Zipper.
(Any)
(Any)
(Any)
Gets the value of the current location.
(T | null)
:
Moves location to the root, constructing any changes made.
Zipper
:
Moves location to the parent. If at the top, returns null.
(Zipper | null)
:
Moves location to the leftmost child. If the current item is a leaf, returns null.
(Zipper | null)
:
Moves location to the left sibling. If the current location is already the leftmost, returns null.
(Zipper | null)
:
Moves location to the right sibling. If the current location is already the rightmost, returns null.
(Zipper | null)
:
Moves location to the leftmost sibling. If the current location is already the leftmost, returns itself.
Zipper
:
Moves location to the rightmost sibling. If the current location is already the rightmost, returns itself.
Zipper
:
Moves location to the next element in depth-first order.
Zipper
:
Moves location to the previous element in depth-first order.
Zipper
:
Returns a boolean indicating if the zipper has been
exhausted by calls to next
.
boolean
:
Returns a boolean indicating if the zipper is at the top.
boolean
:
Returns a boolean indicating if the current location is not a leaf.
boolean
:
Returns a boolean indicating if the current location is a leaf.
boolean
:
Returns a boolean indicating if the item at the current location is the leftmost sibling.
boolean
:
Returns a boolean indicating if the item at the current location is the rightmost sibling.
boolean
:
Alias for isTop
.
boolean
:
Alias for isLeftmost
boolean
:
Alias for isRightmost
boolean
:
Alias for isBranch
boolean
:
Replaces the current item with the given value.
(T)
item to replace the current one with.
Zipper
:
Inserts a new item as the left sibling.
(T)
Zipper
:
Inserts a new item as the right sibling.
(T)
Zipper
:
Inserts a new item as the leftmost child.
(T)
Zipper
:
Inserts a new item as the rightmost child.
(T)
Zipper
:
Removes item at the current location. Returns location that would be previous in depth first search.
Zipper
:
Zipper for nested Arrays.
Don't use with new keyword - use the function plainly
or with ArrayZipper.from([1, 2, 3])
.
(Array)
the data structure to make a zipper for
Zipper
:
Module for implementing visitors to a data structure with zippers.
Every member is importable under zippa
. import { visit, onPre, onPost } from 'zippa'
Visits the data structure in depth-first order, calling one or more visitors on each node, on pre and post events.
The visitor functions are called with three arguments:
If you're visiting for side-effects, you don't have to return anything from your visitor function. To edit items, visit state, or stop the visit, you must return an object which can have zero or more of the following keys:
item
: if supplied, will replace the item at the current location
with the supplied value. The data structure won't change if the value
has the same reference as the current value.state
: if supplied, will update the state of the visit with the
value. State is shared with all visitors.stop
: if truthy, will stop the visitcut
: if truthy, will skip the subtree of the current node.Returns a new data structure of modified items, or the original zipper if the structure wasn't modified.
([Any])
Initial state for the visit
(Zipper)
A Zipper value to visit
Zipper
:
Takes a visitor function that takes an item
and state
argument,
and returns a visitor function that is only invoked on the pre-event.
Equal to:
const myVisitor = (item, state) => console.log('visited item', item);
function visitor(event, item, state) {
if (event === PRE) return myVisitor(item, state);
}
Function
:
visitor function
Takes a visitor function that takes an item
and state
argument,
and returns a visitor function that is only invoked on the post-event.
Equal to:
const myVisitor = (item, state) => console.log('visited item', item);
function visitor(event, item, state) {
if (event === POST) return myVisitor(item, state);
}
Function
:
visitor function
Pre-event identifier.
Post-event identifier.
Module for walking data structures with zippers.
Every member is importable under zippa
. import { walk, preWalk, postWalk } from 'zippa'
Walks the data structure in depth-first order, applying inner and outer functions before and after (respectively) each item's subtree is walked.
Returns a new data structure from modified items, or the original zipper if the structure wasn't modified.
(Function)
function applied to each item before it's subtree is walked
(Function)
function applied to each item after it's subtree was walked
(Zipper)
A Zipper value to walk
Zipper
:
Walks the data structure in depth-first order, applying the function before the item's subtree has been walked.
Returns a new data structure of modified items, or the original zipper if the structure wasn't modified.
(Function)
function applied to each item before it's subtree is walked
(Zipper)
A Zipper value to walk
Zipper
:
Walks the data structure in depth-first order, applying the function after the item's subtree has been walked.
Returns a new data structure of modified items, or the original zipper if the structure wasn't modified.
(Function)
function applied to each item after it's subtree was walked
(Zipper)
A Zipper value to walk
Zipper
: