0 | module Data.SnocList.Lens
4 | import Data.Profunctor
5 | import public Control.Lens
10 | stripPrefix : Eq a => SnocList a -> SnocList a -> Maybe (SnocList a)
11 | stripPrefix qs xs0 = go xs0 zs
13 | drp : SnocList a -> SnocList a -> SnocList a
14 | drp (ps :< _) (xs :< _) = drp ps xs
21 | go : SnocList a -> SnocList a -> Maybe (SnocList a)
22 | go (xs :< _) (ys :< _) = go xs ys
23 | go xs [<] = zipWith const xs0 zs <$ guard (xs == qs)
26 | stripSuffix : Eq a => SnocList a -> SnocList a -> Maybe (SnocList a)
27 | stripSuffix [<] ys = Just ys
28 | stripSuffix (_ :< _) [<] = Nothing
29 | stripSuffix (xs :< x) (ys :< y) = guard (x == y) *> stripSuffix xs ys
34 | prefixed : Eq a => SnocList a -> Prism' (SnocList a) (SnocList a)
35 | prefixed xs = prism' (xs ++) (stripPrefix xs)
39 | suffixed : Eq a => SnocList a -> Prism' (SnocList a) (SnocList a)
40 | suffixed xs = prism' (++ xs) (stripSuffix xs)
44 | reversed : Iso (SnocList a) (SnocList b) (SnocList a) (SnocList b)
45 | reversed = iso reverse reverse
49 | Ixed Nat a (SnocList a) where
53 | Snoc (SnocList a) (SnocList b) a b where
54 | snocIso = iso (\case
56 | xs :< x => Just (xs,x))
57 | (maybe [<] $
uncurry (:<))
59 | snoc_ = prism (uncurry (:<)) (\case
61 | xs :< x => Right (xs,x))
63 | uncons : SnocList a -> a -> (a, SnocList a)
64 | uncons [<] x = (x, [<])
65 | uncons (ys :< y) x = mapSnd (:< x) $
uncons ys y
68 | Cons (SnocList a) (SnocList b) a b where
69 | consIso = iso (\case
71 | xs :< x => Just $
uncons xs x)
72 | (maybe [<] $
uncurry cons)
74 | cons_ = prism (uncurry cons) (\case
76 | xs :< x => Right $
uncons xs x)
79 | Each (SnocList a) (SnocList b) a b where
83 | Num i => IEach i (SnocList a) (SnocList b) a b where