- data Zipper a b
- zipper :: a -> Zipper a a
- close :: Zipper a b -> a
- class ZPath p where
- moveUp :: (Typeable c, Typeable b) => Int -> Zipper a c -> Maybe (Zipper a b)
- focus :: :-> (Zipper a1 a) a
- viewf :: Zipper a b -> b
- atTop :: Zipper a b -> Bool
- data SavedPath a b
- save :: Zipper a b -> SavedPath a b
- saveFromAbove :: (Typeable c, Typeable b) => Int -> Zipper a c -> Maybe (SavedPath b c)
- savedLens :: (Typeable a, Typeable b) => SavedPath a b -> a :-> b
- closeSaving :: Zipper a b -> (SavedPath a b, a)
- moveUpSaving :: (Typeable c, Typeable b) => Int -> Zipper a c -> Maybe (Zipper a b, SavedPath b c)
- restore :: (ZPath p, Typeable a, Typeable b) => p a b -> a -> Zipper a b
- type Zipper1 a = Zipper a a
- (.+) :: (ZPath p, Typeable b, Typeable c) => Zipper a b -> p b c -> Zipper a c
- (.>) :: Zipper a b -> b -> Zipper a b
- (.-) :: (Typeable c, Typeable b) => Zipper a c -> Int -> Maybe (Zipper a b)
- (?+) :: (ZPath p, Typeable b, Typeable c) => Maybe (Zipper a b) -> p b c -> Maybe (Zipper a c)
- (?>) :: Maybe (Zipper a b) -> b -> Maybe (Zipper a b)
- (?-) :: (Typeable c, Typeable b) => Maybe (Zipper a c) -> Int -> Maybe (Zipper a b)
- module Data.Record.Label
- class Typeable a
Basic Zipper functionality
Creating and closing Zippers
Moving around
Types of the ZPath class act as references to paths down through a datatype.
Currently lenses from fclabels
and SavedPath types are instances
moveUp :: (Typeable c, Typeable b) => Int -> Zipper a c -> Maybe (Zipper a b)Source
Move up n levels as long as the type of the parent is what the programmer is expecting and we aren't already at the top. Otherwise return Nothing.
Querying
Advanced functionality
Saving positions in a Zipper
stores the path used to return to the same location in a data structure as the one we just exited. You can also extract a lens from a SavedPath that points to that location:
save :: Zipper a b -> SavedPath a bSource
Return a SavedPath type encapsulating the current location in the Zipper. This lets you return to a location in your data type after closing the Zipper.
saveFromAbove :: (Typeable c, Typeable b) => Int -> Zipper a c -> Maybe (SavedPath b c)Source
return a SavedPath from n levels up to the current level
savedLens :: (Typeable a, Typeable b) => SavedPath a b -> a :-> bSource
Extract a composed lens that points to the location we SavedPath. This lets us modify, set or get a location that we visited with our Zipper after closing the Zipper.
closeSaving :: Zipper a b -> (SavedPath a b, a)Source
moveUpSaving :: (Typeable c, Typeable b) => Int -> Zipper a c -> Maybe (Zipper a b, SavedPath b c)Source
Move up a level as long as the type of the parent is what the programmer is expecting and we aren't already at the top. Otherwise return Nothing.
Recalling positions:
restore :: (ZPath p, Typeable a, Typeable b) => p a b -> a -> Zipper a bSource
Return to a previously SavedPath location within a data-structure. Saving and restoring lets us for example: find some location within our structure using a Zipper, save the location, fmap over the entire structure, and then return to where we were:
Convenience operators, types, and exports
type Zipper1 a = Zipper a aSource
a simple type synonym for a Zipper where the type at the focus is the same as the type of the outer (unzippered) type. Cleans up type signatures for simple recursive types:
Operators
(.+) :: (ZPath p, Typeable b, Typeable c) => Zipper a b -> p b c -> Zipper a cSource
moveTo
with arguments flipped. Operator plays on the idea of addition of
levels onto the focus.
(.-) :: (Typeable c, Typeable b) => Zipper a c -> Int -> Maybe (Zipper a b)Source
moveUp
with arguments flipped. Operator syntax comes from the idea of
moving up as subtraction.
(?+) :: (ZPath p, Typeable b, Typeable c) => Maybe (Zipper a b) -> p b c -> Maybe (Zipper a c)Source
Export Typeable class and fclabels package
module Data.Record.Label
class Typeable a
The class Typeable
allows a concrete representation of a type to
be calculated.