tur/zipper
stdlib/zipper.tur
defn
zipper-new
(zipper-new [left-arr left-len focus right-arr right-len] :int)
construct a Zipper from pre-built left/right arrays.
Parameters
| left-arr | pointer to left elements array (nearest-first) (:int) | |
| left-len | number of left elements (:int) | |
| focus | the focused element (:int) | |
| right-arr | pointer to right elements array (nearest-first) (:int) | |
| right-len | number of right elements (:int) |
Since: Phase CA0
defn
zipper-from-array
(zipper-from-array [arr len idx] :int)
build a Zipper from a flat C array with a given focus index.
Parameters
| arr | pointer to a flat int64_t array (:int) | |
| len | number of elements in the array (:int) | |
| idx | index of the initial focus position (:int) |
Since: Phase CA0
defn
zipper-focus
(zipper-focus [z] :int)
return the element at the current focus position.
Parameters
| z | zipper pointer (:int) |
Since: Phase CA0
defn
zipper-len
(zipper-len [z] :int)
return the total number of elements in a zipper.
Parameters
| z | zipper pointer (:int) |
Since: Phase CA0
defn
zipper-peek
(zipper-peek [z offset def-val] :int)
read an element at an offset relative to the current focus.
Parameters
| z | zipper pointer (:int) | |
| offset | offset from focus: 0=focus, -1=left neighbour, +1=right neighbour (:int) | |
| def-val | default value to return when offset is out of bounds (:int) |
Since: Phase CA0
defn
zipper-left
(zipper-left [z] :int)
move the focus one step to the left.
Parameters
| z | zipper pointer (:int) |
Since: Phase CA0
defn
zipper-right
(zipper-right [z] :int)
move the focus one step to the right.
Parameters
| z | zipper pointer (:int) |
Since: Phase CA0
defn
zipper-to-array
(zipper-to-array [z] :int)
flatten a Zipper back to a left-to-right int64_t array.
Parameters
| z | zipper pointer (:int) |
Since: Phase CA0
definstance
Comonad[zipper]
(definstance Comonad [zipper])
Comonad instance for the 1D list Zipper.
Since: Phase CA0
Internal definitions
__zipper_extract-- extract the focused element from a zipper.__zipper_extend-- apply fn at every position and return a new zipper of results.__zipper_duplicate-- produce a zipper of zippers (each position focused).