A library for a template type.
If you're working with Chars, check out Zipper.StringString
Zipper.ListList.AdvancedZipper.StringStringPassed to the user-provided function by indexedMap and similar functions to specify the current element's location in various reference frames
Create an empty zipper
empty --> ( [], [] )fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
--> ( [ 3, 2, 1 ], [ 4, 5, 6 ] )( [ 3, 2, 1 ], 4, [ 5, 6, 7 ] )
|> fromZipperListElemList
--> ( [ 3, 2, 1 ], [ 5, 6, 7 ] )( [ 3, 2, 1 ], [ 4, 5, 6 ], [ 7, 8, 9 ] )
|> fromZipperListListList
--> ( [ 3, 2, 1 ], [ 7, 8, 9 ] )( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> fromTuple
|> toTuple
--> ( [ 1, 2, 3 ], [ 4, 5, 6 ] )fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> toList
--> [ 1, 2, 3, 4, 5, 6 ]fromTuple ( [ 1, 2, 3 ], [ 5, 6, 7 ] )
|> toZipperListElemList 4
--> ( [ 3, 2, 1 ], 4, [ 5, 6, 7 ] )fromTuple ( [ 1, 2, 3 ], [ 7, 8, 9 ] )
|> toZipperListListList [ 4, 5, 6 ]
--> ( [ 3, 2, 1 ], [ 4, 5, 6 ], [ 7, 8, 9 ] )fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> length
--> 6fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
|> position
--> 3fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
|> getLeft
--> [ 1, 2, 3 ]fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
|> getRight
--> [ 4, 5 ]fromTuple ( [ '1', '2', '3' ], [ '4', '5', '6' ] )
|> setLeft [ 'a', 'b', 'c' ]
--> fromTuple ( [ 'a', 'b', 'c' ], [ '4', '5', '6' ] )fromTuple ( [ '1', '2', '3' ], [ '4', '5', '6' ] )
|> setRight [ 'a', 'b', 'c' ]
--> fromTuple ( [ '1', '2', '3' ], [ 'a', 'b', 'c' ] )fromTuple ( [ 1, 2, 3 ], [ 4, 5 ] )
|> map String.fromInt
--> fromTuple ( [ "1", "2", "3" ], [ "4", "5" ] )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 ] )fromTuple ( [ "a", "b", "c" ], [ "d", "e", "f" ] )
|> update (String.join "" >> List.repeat 2 >> List.indexedMap Tuple.pair)
--> fromTuple ( [ ( 0, "abc" ), ( 1, "abc" ) ], [ ( 0, "def" ), ( 1, "def" ) ] )fromTuple ( [ 1, 2, 3, 4 ], [ 1, 2, 3, 4 ] )
|> filter (\n -> modBy 2 n == 0)
--> fromTuple ( [ 2, 4 ], [ 2, 4 ] )fromTuple ( [ 1, 0 ], [ 4, 2, 1, 7, 8 ] )
|> indexedFilter (\{first} val -> val > first)
--> fromTuple ( [ 1 ], [ 4, 7, 8 ] )fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> moveLeft
--> Just (fromTuple ( [ 1, 2 ], [ 3, 4, 5, 6 ] ))
fromTuple ( [], [ 4, 5, 6 ] )
|> moveLeft
--> NothingfromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> tryMoveLeft
--> fromTuple ( [ 1, 2 ], [ 3, 4, 5, 6 ] )
fromTuple ( [], [ 4, 5, 6 ] )
|> tryMoveLeft
--> fromTuple ( [], [ 4, 5, 6 ] )fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> moveRight
--> Just (fromTuple ( [ 1, 2, 3, 4 ], [ 5, 6 ] ))
fromTuple ( [ 1, 2, 3 ], [] )
|> moveRight
--> NothingfromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> tryMoveRight
--> fromTuple ( [ 1, 2, 3, 4 ], [ 5, 6 ] )
fromTuple ( [ 1, 2, 3 ], [] )
|> tryMoveRight
--> fromTuple ( [ 1, 2, 3 ], [] )fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> moveToFirst
--> fromTuple ( [], [ 1, 2, 3, 4, 5, 6 ] )fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> moveToLast
--> fromTuple ( [ 1, 2, 3, 4, 5, 6 ], [] )fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> insertFirst 0
--> fromTuple ( [ 0, 1, 2, 3 ], [ 4, 5, 6 ] )fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> insertLast 0
--> fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6, 0 ] )fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> insertLeftOfSplit 0
--> fromTuple ( [ 1, 2, 3, 0 ], [ 4, 5, 6 ] )fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> insertRightOfSplit 0
--> fromTuple ( [ 1, 2, 3 ], [ 0, 4, 5, 6 ] )fromTuple ( [ 1, 4, 2 ], [ 2, 3 ] )
|> sortKeepIndex
--> fromTuple ( [ 1, 2, 2 ], [ 3, 4 ] )fromTuple ( [ 1, 2, 3 ], [ 4, 5, 6 ] )
|> reverse
--> fromTuple ( [ 6, 5, 4 ], [ 3, 2, 1 ] )zipper : Zipper Int
zipper = ( [ 0, 0, 0 ], [ 0, 0, 0 ] )
indexRelativeToAbsolute zipper (LeftIndex 3) --> -1
indexRelativeToAbsolute zipper (LeftIndex 2) --> 0
indexRelativeToAbsolute zipper (LeftIndex 0) --> 2
indexRelativeToAbsolute zipper (RightIndex 0) --> 3
indexRelativeToAbsolute zipper (RightIndex 2) --> 5
indexRelativeToAbsolute zipper (RightIndex 3) --> 6
A list type that tracks a split location