coreygirard/elm-zipper/1.0.0

Zipper.ListList.Advanced

A library for a template type.

Note: If all zipper elements are of the same type, use Zipper.ListList instead. It has a simpler API.

Definition

type alias Zipper a b =
( List a, List b )

A list type that must contain at least one element

Create

empty : Zipper a b

Create a new Zipper

Utilities

reverse : Zipper a b -> Zipper b a
length : Zipper a b -> Int
lengthLeft : Zipper a b -> Int
lengthRight : Zipper a b -> Int
position : Zipper a b -> Int

Get

getLeft : Zipper a b -> List a
getRight : Zipper a b -> List b

Set

setLeft : List a -> Zipper a b -> Zipper a b
setRight : List b -> Zipper a b -> Zipper a b

Insert

insertAtFirst : a -> Zipper a b -> Zipper a b
insertAtLast : b -> Zipper a b -> Zipper a b
insertToLeft : a -> Zipper a b -> Zipper a b
insertToRight : b -> Zipper a b -> Zipper a b

Update

updateLeft : (List a -> List a) -> Zipper a b -> Zipper a b
updateRight : (List b -> List b) -> Zipper a b -> Zipper a b

Move

moveToRight : (b -> a) -> Zipper a b -> Maybe (Zipper a b)

Attempt to move split to right

moveToLeft : (a -> b) -> Zipper a b -> Maybe (Zipper a b)

Attempt to move split to left

moveLeftUntil : (a -> b) -> (List a -> List b -> Bool) -> Zipper a b -> Maybe (Zipper a b)
tryMoveToRight : (b -> a) -> Zipper a b -> Zipper a b

Attempt to move split to right, return unchanged zipper on failure

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

Attempt to move split to left, return unchanged zipper on failure

moveRightUntil : (b -> a) -> (List a -> List b -> Bool) -> Zipper a b -> Maybe (Zipper a b)
moveToN : (a -> b) -> (b -> a) -> Int -> Zipper a b -> Maybe (Zipper a b)

Attempt to move the split by specifying the length of the resulting left list. If the split would be invalid, eg n < 0 or n > length zipper, returns Nothing.

( [ 2, 1 ], [ 3, 4 ] )
    |> moveToN identity identity -1
    == Nothing


( [ 2, 1 ], [ 3, 4 ] )
    |> moveToN identity identity 1
    == Just ( [ 1 ], [ 2, 3, 4 ] )


( [ 2, 1 ], [ 3, 4 ] )
    |> moveToN identity identity 4
    == Just ( [ 4, 3, 2, 1 ], [] )

Map

map : (a1 -> a2) -> (b1 -> b2) -> Zipper a1 b1 -> Zipper a2 b2
mapLeft : (a -> a) -> Zipper a b -> Zipper a b
mapRight : (b -> b) -> Zipper a b -> Zipper a b