wernerdegroot/listzipper/3.0.0

NOTE: this package is not compatible with Elm 0.19.1

List.Zipper

A zipper for List.

The Zipper type

type Zipper a
= Zipper (List a) a (List 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).

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.

last : Zipper a -> Zipper a

Move the focus to the last element of the list.

find : (a -> 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).