A library for a template type.
If you're working with Chars, check out Zipper.StringString
Zipper.ListList.AdvancedZipper.StringStringfromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
|> lengthRight
--> 2fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
|> positionFromEnd
--> 2zipper : 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 --> Nothingzipper : 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) --> NothingfromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
|> setAt 2 0
--> Just (fromTuple ( [ 1, 2, 0 ], [ 4, 5 ] ))fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
|> setAt 2 0
--> Just (fromTuple ( [ 1, 2, 0 ], [ 4, 5 ] ))fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
|> setAtRelative (LeftIndex 1) 0
--> Just (fromTuple ( [ 1, 0, 3 ], [ 4, 5 ] ))fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
|> setAtRelative (LeftIndex 1) 0
--> Just (fromTuple ( [ 1, 0, 3 ], [ 4, 5 ] ))fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
|> mapSeparately ((+) 10) ((+) 20)
--> fromTuple ( [ 11, 12, 13 ], [ 24, 25 ] )fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
|> mapLeft ((+) 10)
--> fromTuple ( [ 11, 12, 13 ], [ 4, 5 ] )fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
|> mapRight ((+) 10)
--> fromTuple ( [ 1, 2, 3 ], [ 14, 15 ] )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 ] )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)
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)
fromTuple ( [ "a", "b", "c" ], [ "d", "e", "f" ] )
|> updateSeparately
(String.join "" >> List.singleton)
(String.join "-" >> List.singleton)
--> fromTuple ( [ "abc" ], [ "d-e-f" ] )fromTuple ( [ "a", "b", "c" ], [ "d", "e", "f" ] )
|> updateLeft (String.join "" >> List.singleton)
--> fromTuple ( [ "abc" ], [ "d", "e", "f" ] )fromTuple ( [ "a", "b", "c" ], [ "d", "e", "f" ] )
|> updateRight (String.join "" >> List.singleton)
--> fromTuple ( [ "a", "b", "c" ], [ "def" ] )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)
--> NothingfromTuple ( [ 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 ] )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 ] )Set selection to Nth element
Set selection to Nth element