wernerdegroot / listzipper / List.Zipper

A zipper for List.

The Zipper type


type Zipper a

The Zipper type.

Constructing a Zipper

singleton : a -> Zipper a

Construct a Zipper focussed on the first element of a singleton list.

fromList : List a -> Maybe (Zipper a)

Construct a Zipper from a list. The Zipper will focus on the first element (if there is a first element).

fromCons : a -> List a -> Zipper a

Construct a Zipper from the first element and a list. The Zipper will focus on the first element.

from : List a -> a -> List a -> Zipper a

Construct a Zipper from before, current, after. The order is preserved, so (from [1,2,3] 4 [5,6] |> toList) == [1,2,3,4,5,6].

withDefault : a -> Maybe (Zipper a) -> Zipper a

Provide an alternative when constructing a Zipper fails.

Accessors

before : Zipper a -> List a

Returns all elements before the element the Zipper is focussed on.

current : Zipper a -> a

Returns the element the Zipper is currently focussed on.

after : Zipper a -> List a

Returns all elements after the element the Zipper is focussed on

toList : Zipper a -> List a

Reconstruct the list.

Mapping

map : (a -> b) -> Zipper a -> Zipper b

Apply a function to every element in the Zipper.

mapBefore : (List a -> List a) -> Zipper a -> Zipper a

Apply a function to all elements before the element the Zipper is focussed on.

mapCurrent : (a -> a) -> Zipper a -> Zipper a

Apply a function to the element the Zipper is focussed on.

mapAfter : (List a -> List a) -> Zipper a -> Zipper a

Apply a function to all elements after the element the Zipper is focussed on.

Moving around

first : Zipper a -> Zipper a

Move the focus to the first element of the list.

previous : Zipper a -> Maybe (Zipper a)

Move the focus to the element before the element the Zipper is currently focussed on (if there is such an element).

next : Zipper a -> Maybe (Zipper a)

Move the focus to the element after the element the Zipper is currently focussed on (if there is such an element).

last : Zipper a -> Zipper a

Move the focus to the last element of the list.

find : (a -> Basics.Bool) -> Zipper a -> Maybe (Zipper a)

Returns a Zipper focussed on the first element for which the predicate returns True (starting from a given Zipper). Note that this function does not search the entire list, but starts searching from the current element.

findFirst : (a -> Basics.Bool) -> Zipper a -> Maybe (Zipper a)

Returns a Zipper focussed on the first element for which the predicate returns True (starting from the first element of a given Zipper).

findNext : (a -> Basics.Bool) -> Zipper a -> Maybe (Zipper a)

Returns a Zipper focussed on the first element for which the predicate returns True (starting from the next element of a given Zipper if there is a next element).

Predicates

isLast : Zipper a -> Basics.Bool

Checks if the currently focused element is the last one.

isFirst : Zipper a -> Basics.Bool

Checks if the currently focused element is the first one.