Data.Zipper.ArrayZipper
- Package
- purescript-arrays-zipper
- Repository
- JordanMartinez/purescript-arrays-zipper
#ArrayZipper Source
newtype ArrayZipper aAn immutable Zipper for an Array. Modifications are O(n) due to creating
a new array rather than mutating the underlying array. Navigating to a
new focus element is O(1) regardless of how far away from the current
focus that element is.
Instances
#asArrayZipper Source
asArrayZipper :: forall a. a -> ArrayZipper aCreates an Array Zipper from a single element. This will be stored
internally as a 1-element array. To further build upon this array,
see push* functions.
#toArrayZipperFirst Source
toArrayZipperFirst :: forall a. Array a -> Maybe (ArrayZipper a)Returns Nothing if the array is empty. Otherwise, returns an ArrayZipper
with the first element as the focus.
#toArrayZipperLast Source
toArrayZipperLast :: forall a. Array a -> Maybe (ArrayZipper a)Returns Nothing if the array is empty. Otherwise, returns an ArrayZipper
with the last element as the focus.
#toArrayZipperAt Source
toArrayZipperAt :: forall a. Int -> Array a -> Maybe (ArrayZipper a)Returns Nothing if the array is empty. Otherwise, returns an ArrayZipper
with the element at the given index as the focus. The given index
will be clamped within the array's bounds to ensure it always refers
to a valid element in the array. To return Nothing on an invalid index,
see toArrayZipperAt'.
#toArrayZipperAt' Source
toArrayZipperAt' :: forall a. Int -> Array a -> Maybe (ArrayZipper a)Returns Nothing if the array is empty or if the given index is
outside the bounds of the array. Otherwise, returns an ArrayZipper
with the element at the given index as the focus. To return Just zipper
by clamping an invalid index, so that it is within the array, see
toArrayZipperAt.
#exposeArray Source
exposeArray :: forall a. ArrayZipper a -> Array aExposes the underlying array. Note: any mutations to this array via
unsafeThaw will invalidate the constraints guaranteed by ArrayZipper.
#exposeMaxIndex Source
exposeMaxIndex :: forall a. ArrayZipper a -> IntExposes the index of the last element
#exposeFocusIndex Source
exposeFocusIndex :: forall a. ArrayZipper a -> IntExposes the index of the focused element
#hasPrev Source
hasPrev :: forall a. ArrayZipper a -> BooleanReturns true if prev will return a Just
#hasNext Source
hasNext :: forall a. ArrayZipper a -> BooleanReturns true if prev will return a Just
#prev Source
prev :: forall a. ArrayZipper a -> Maybe (ArrayZipper a)Returns Nothing if the focus element is the first element in the array.
Otherwise, returns Just where the new focus element is the previous
element.
#next Source
next :: forall a. ArrayZipper a -> Maybe (ArrayZipper a)Returns Nothing if the focus element is the last element in the array.
Otherwise, returns Just where the new focus element is the next
element.
#shiftFocusBy Source
shiftFocusBy :: forall a. (Int -> Int) -> ArrayZipper a -> ArrayZipper aUse a function to focus a different element in the array by using the
zipper's current focus index. If the resulting index is outside the bounds
of the array, the index will refer to the first or last element, whichever
is closer to the output of the function. To prevent clamping
and return Nothing if the output of the function is an invalid index,
see shiftFocusBy'.
#shiftFocusBy' Source
shiftFocusBy' :: forall a. (Int -> Int) -> ArrayZipper a -> Maybe (ArrayZipper a)Use a function to focus a different element in the array by using the
zipper's current focus index. If the resulting index is outside the bounds
of the array, Nothing is returned. If it's a valid index, Just zipper
is returned.
#shiftFocusFirst Source
shiftFocusFirst :: forall a. ArrayZipper a -> ArrayZipper aChanges the focus element to the first element in the array.
#shiftFocusLast Source
shiftFocusLast :: forall a. ArrayZipper a -> ArrayZipper aChanges the focus element to the last element in the array.
#getFocus Source
getFocus :: forall a. ArrayZipper a -> aReturns the focus element.
#setFocus Source
setFocus :: forall a. a -> ArrayZipper a -> ArrayZipper aSets the focus element. O(n)
#modifyFocus Source
modifyFocus :: forall a. (a -> a) -> ArrayZipper a -> ArrayZipper aUses a function to update the focus element. O(n)
#pushPrev Source
pushPrev :: forall a. a -> ArrayZipper a -> ArrayZipper aInserts an element in front of / to the left of the focus element. O(n)
#pushNext Source
pushNext :: forall a. a -> ArrayZipper a -> ArrayZipper aInserts an element behind / to the right of the focus element. O(n)
#pushPrevRefocus Source
pushPrevRefocus :: forall a. a -> ArrayZipper a -> ArrayZipper aInserts an element in front of / to the left of the focus element
and sets this new element as the focus element. O(n)
#pushNextRefocus Source
pushNextRefocus :: forall a. a -> ArrayZipper a -> ArrayZipper aInserts an element behind / to the right of the focus element
and sets this new element as the focus element. O(n)
- Modules
- Data.
Zipper. ArrayZipper