tur/zipper
stdlib/zipper.tur
typed Zipper[A]: 1D list zipper with typed focus and neighbors.
Since: Phase TC2-B
defstruct
Zipper
(defstruct Zipper [A])
parameterized 1D list zipper with element type A.
Since: Phase TC2
defn
zipper-new
(zipper-new [left :ptr<void> left-len :int focus :int right :ptr<void> right-len :int])
create a Zipper[A] from left array, focus, and right array.
Parameters
| left | pointer to left neighbor array (int64_t*); leftmost = furthest from focus | |
| left-len | number of elements in left | |
| focus | focused element of type A | |
| right | pointer to right neighbor array (int64_t*); rightmost = furthest from focus | |
| right-len | number of elements in right |
Returns
A new Zipper[A].
Example
(let [l (make-left-arr)
r (make-right-arr)
z (zipper-new l 2 5 r 2)]
(free l) (free r) ; caller retains l / r ownership
... use z ...
(zipper-free z)) ; frees the copies inside z
Since: Phase TC2
defn
zipper-focus
(zipper-focus [z :int])
return the focused element of a Zipper[A].
Parameters
| z | Zipper[A] |
Returns
The focused element of type A.
Example
(zipper-focus z) ; => focused element
Since: Phase TC2
defn
zipper-move-left
(zipper-move-left [z :int])
move the focus one step to the left; returns Option[Zipper[A]].
Parameters
| z | Zipper[A] |
Returns
some(new-zipper) if left neighbor exists, none otherwise.
Example
(zipper-move-left z) ; => some(z') or none
Since: Phase TC2
defn
zipper-move-right
(zipper-move-right [z :int])
move the focus one step to the right; returns Option[Zipper[A]].
Parameters
| z | Zipper[A] |
Returns
some(new-zipper) if right neighbor exists, none otherwise.
Example
(zipper-move-right z) ; => some(z') or none
Since: Phase TC2
defn
zipper-free
(zipper-free [z :int])
free a Zipper[A] and its neighbor arrays.
Parameters
| z | Zipper[A] to free |
Example
(zipper-free z)
Since: Phase TC2