coreygirard/elm-zipper/1.0.0

Zipper.ListList.Extra

A library for a template type.

If you're working with Chars, check out Zipper.StringString

Definition

Create

To

Length

lengthLeft : Zipper a -> Int
fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
    |> lengthLeft
    --> 3
lengthRight : Zipper a -> Int
fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
    |> lengthRight
    --> 2
positionFromEnd : Zipper a -> Int
fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
    |> positionFromEnd
    --> 2

Get

getAt : Int -> Zipper a -> Maybe a
zipper : Zipper Int
zipper = fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )


zipper |> getAt -1 --> Nothing


zipper |> getAt 0 --> Just 1


zipper |> getAt 2 --> Just 3


zipper |> getAt 3 --> Just 4


zipper |> getAt 4 --> Just 5


zipper |> getAt 5 --> Nothing
getAtRelative : RelativeIndex -> Zipper a -> Maybe a
zipper : Zipper Int
zipper = fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )


zipper |> getAtRelative (LeftIndex 3) --> Nothing


zipper |> getAtRelative (LeftIndex 2) --> Just 1


zipper |> getAtRelative (LeftIndex 0) --> Just 3


zipper |> getAtRelative (RightIndex 0) --> Just 4


zipper |> getAtRelative (RightIndex 2) --> Just 6


zipper |> getAtRelative (RightIndex 3) --> Nothing

Set

setAt : Int -> a -> Zipper a -> Maybe (Zipper a)
fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
    |> setAt 2 0
    --> Just (fromTuple ( [ 1, 2, 0 ], [ 4, 5 ] ))
trySetAt : Int -> a -> Zipper a -> Zipper a
fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
    |> setAt 2 0
    --> Just (fromTuple ( [ 1, 2, 0 ], [ 4, 5 ] ))
setAtRelative : RelativeIndex -> a -> Zipper a -> Maybe (Zipper a)
fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
    |> setAtRelative (LeftIndex 1) 0
    --> Just (fromTuple ( [ 1, 0, 3 ], [ 4, 5 ] ))
trySetAtRelative : RelativeIndex -> a -> Zipper a -> Zipper a
fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
    |> setAtRelative (LeftIndex 1) 0
    --> Just (fromTuple ( [ 1, 0, 3 ], [ 4, 5 ] ))

Map

mapSeparately : (a -> b) -> (a -> b) -> Zipper a -> Zipper b
fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
    |> mapSeparately ((+) 10) ((+) 20)
    --> fromTuple ( [ 11, 12, 13 ], [ 24, 25 ] )
mapLeft : (a -> a) -> Zipper a -> Zipper a
fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
    |> mapLeft ((+) 10)
    --> fromTuple ( [ 11, 12, 13 ], [ 4, 5 ] )
mapRight : (a -> a) -> Zipper a -> Zipper a
fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
    |> mapRight ((+) 10)
    --> fromTuple ( [ 1, 2, 3 ], [ 14, 15 ] )
indexedMapSeparately : (Position -> a -> b) -> (Position -> a -> b) -> Zipper a -> Zipper b
fromTuple ( [ 0, 0 ], [ 0, 0, 0, 0 ] )
    |> indexedMap (\{first} _ -> first)
    --> fromTuple ( [ 0, 1 ], [ 2, 3, 4, 5 ] )


fromTuple ( [ 0, 0 ], [ 0, 0, 0, 0 ] )
    |> indexedMap (\{last} _ -> last)
    --> fromTuple ( [ 5, 4 ], [ 3, 2, 1, 0 ] )


fromTuple ( [ 0, 0 ], [ 0, 0, 0, 0 ] )
    |> indexedMap (\{leftEdge} _ -> leftEdge)
    --> fromTuple ( [ 0, 1 ], [ 0, 1, 2, 3 ] )


fromTuple ( [ 0, 0 ], [ 0, 0, 0, 0 ] )
    |> indexedMap (\{rightEdge} _ -> rightEdge)
    --> fromTuple ( [ 1, 0 ], [ 3, 2, 1, 0 ] )
indexedMapLeft : (Position -> a -> a) -> Zipper a -> Zipper a

Similar to indexedMap except only applied to the left side. Note the slightly different type signature. See Zipper.ListList.Advanced.indexedMapLeft for a function that is capable of (List a, List a) -> (List b, List a)

indexedMapRight : (Position -> a -> a) -> Zipper a -> Zipper a

Similar to indexedMap except only applied to the right side. Note the slightly different type signature. See Zipper.ListList.Advanced.indexedMapRight for a function that is capable of (List a, List a) -> (List a, List b)

Update

updateSeparately : (List a -> List b) -> (List a -> List b) -> Zipper a -> Zipper b
fromTuple ( [ "a", "b", "c" ], [ "d", "e", "f" ] )
    |> updateSeparately
        (String.join "" >> List.singleton)
        (String.join "-" >> List.singleton)
    --> fromTuple ( [ "abc" ], [ "d-e-f" ] )
updateLeft : (List a -> List a) -> Zipper a -> Zipper a
fromTuple ( [ "a", "b", "c" ], [ "d", "e", "f" ] )
    |> updateLeft (String.join "" >> List.singleton)
    --> fromTuple ( [ "abc" ], [ "d", "e", "f" ] )
updateRight : (List a -> List a) -> Zipper a -> Zipper a
fromTuple ( [ "a", "b", "c" ], [ "d", "e", "f" ] )
    |> updateRight (String.join "" >> List.singleton)
    --> fromTuple ( [ "a", "b", "c" ], [ "def" ] )
updateAt : Int -> (a -> a) -> Zipper a -> Maybe (Zipper a)
tryUpdateAt : Int -> (a -> a) -> Zipper a -> Zipper a
updateAtRelative : RelativeIndex -> (a -> a) -> Zipper a -> Maybe (Zipper a)
fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
    |> updateAtRelative (LeftIndex 0) ((+) 10)
    --> Just (fromTuple ( [ 1, 2, 13 ], [ 4, 5, 6 ] ))


fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
    |> updateAtRelative (RightIndex 2) ((+) 10)
    --> Just (fromTuple ( [ 1, 2, 3 ], [ 4, 5, 16 ] ))


fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
    |> updateAtRelative (RightIndex 10) ((+) 10)
    --> Nothing
tryUpdateAtRelative : RelativeIndex -> (a -> a) -> Zipper a -> Zipper a
fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
    |> tryUpdateAtRelative (LeftIndex 0) ((+) 10)
    --> fromTuple ( [ 1, 2, 13 ], [ 4, 5, 6 ] )


fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
    |> tryUpdateAtRelative (RightIndex 10) ((+) 10)
    --> fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )

Filter

filterSeparately : (a -> Bool) -> (a -> Bool) -> Zipper a -> Zipper a
fromTuple ( [ 1, 2, 3, 4 ], [ 1, 2, 3, 4 ] )
    |> filterSeparately (\n -> modBy 2 n /= 0) (\n -> modBy 2 n == 0)
    --> fromTuple ( [ 1, 3 ], [ 2, 4 ] )
filterLeft : (a -> Bool) -> Zipper a -> Zipper a
filterRight : (a -> Bool) -> Zipper a -> Zipper a
indexedFilterLeft : (Position -> a -> Bool) -> Zipper a -> Zipper a
indexedFilterRight : (Position -> a -> Bool) -> Zipper a -> Zipper a

Move

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

Set selection to Nth element

tryMoveToN : Int -> Zipper a -> Zipper a

Set selection to Nth element

Insert

Sort

sortByKeepIndex : (a -> comparable) -> Zipper a -> Zipper a
sortWithKeepIndex : (a -> a -> Order) -> Zipper a -> Zipper a

Reverse

reverseLeft : Zipper a -> Zipper a
reverseRight : Zipper a -> Zipper a

Swap

swap : Int -> Int -> Zipper a -> Maybe (Zipper a)
trySwap : Int -> Int -> Zipper a -> Zipper a

Indexes