This module provides a Zipper
with fairly strong type checking
The code here is inspired by Brandon Simmons' zippo
but uses a different approach to represent the Zipper
makes the whole thing look like his breadcrumb trail, and can move
side-to-side through traversals.
Some examples types:
Since individual levels of a Zipper
are managed by an arbitrary
, you can move left and right through the
selecting neighboring elements.
>>> zipper ("hello","world") & downward _1 & fromWithin traverse & focus .~ 'J' & rightmost & focus .~ 'y' & rezip
This is particularly powerful when compiled with plate
for walking down into self-similar
children in syntax trees and other structures.
Given keys in ascending order you can jump directly to a given key
. When used with traversals for balanced tree-like
structures such as an IntMap
, searching for a key
can be done in logarithmic time.