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.

left-arrpointer to left elements array (nearest-first) (:int)
left-lennumber of left elements (:int)
focusthe focused element (:int)
right-arrpointer to right elements array (nearest-first) (:int)
right-lennumber 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.

arrpointer to a flat int64_t array (:int)
lennumber of elements in the array (:int)
idxindex of the initial focus position (:int)

Since: Phase CA0

defn

zipper-focus

(zipper-focus [z] :int)

return the element at the current focus position.

zzipper pointer (:int)

Since: Phase CA0

defn

zipper-len

(zipper-len [z] :int)

return the total number of elements in a zipper.

zzipper 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.

zzipper pointer (:int)
offsetoffset from focus: 0=focus, -1=left neighbour, +1=right neighbour (:int)
def-valdefault 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.

zzipper pointer (:int)

Since: Phase CA0

defn

zipper-right

(zipper-right [z] :int)

move the focus one step to the right.

zzipper 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.

zzipper 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).