on master help sign in
Pass all doctests
3a492a6Csongor Kiss
src/Data/Generics/Internal/Profunctor/Lens.hs−7
@@ -23,7 +23,6 @@ module Data.Generics.Internal.Profunctor.Lens where
23
23
24import Data.Profunctor (Profunctor(..), Strong(..))
24import Data.Profunctor (Profunctor(..), Strong(..))
25import Data.Bifunctor
25import Data.Bifunctor
26−import Data.Profunctor.Unsafe ((#.))
27import Data.Tagged
26import Data.Tagged
28import GHC.Generics
27import GHC.Generics
29import Data.Generics.Internal.Profunctor.Iso
28import Data.Generics.Internal.Profunctor.Iso
@@ -63,12 +62,6 @@ idLens :: ALens a b a b
63idLens = ALens (fork (const ()) id) snd
62idLens = ALens (fork (const ()) id) snd
64{-# INLINE idLens #-}
63{-# INLINE idLens #-}
65
64
66−
67−
68−build :: (Tagged b b -> Tagged t t) -> b -> t
69−build p = unTagged . p . Tagged
70−
71−
72-- | Lens focusing on the first element of a product
65-- | Lens focusing on the first element of a product
73first :: Lens ((a :*: b) x) ((a' :*: b) x) (a x) (a' x)
66first :: Lens ((a :*: b) x) ((a' :*: b) x) (a x) (a' x)
74first
67first
src/Data/Generics/Internal/VL/Prism.hs+4−1
@@ -23,7 +23,7 @@ module Data.Generics.Internal.VL.Prism where
23import Data.Functor.Identity (Identity(..))
23import Data.Functor.Identity (Identity(..))
24import Data.Profunctor (Choice(..), Profunctor(..))
24import Data.Profunctor (Choice(..), Profunctor(..))
25import Data.Coerce
25import Data.Coerce
26−import Data.Generics.Internal.Profunctor.Prism (Market (..), plus, idPrism, prismPRavel)
26+import Data.Generics.Internal.Profunctor.Prism (Market (..), plus, idPrism)
27import Data.Tagged
27import Data.Tagged
28import Data.Profunctor.Unsafe ((#.), (.#))
28import Data.Profunctor.Unsafe ((#.), (.#))
29import Data.Monoid (First (..))
29import Data.Monoid (First (..))
@@ -45,6 +45,9 @@ s ^? l = getFirst (fmof l (First #. Just) s)
45match :: Prism s t a b -> s -> Either t a
45match :: Prism s t a b -> s -> Either t a
46match k = withPrism k $ \_ _match -> _match
46match k = withPrism k $ \_ _match -> _match
47
47
48+(#) :: (Tagged b (Identity b) -> Tagged t (Identity t)) -> b -> t
49+(#) = build
50+
48prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
51prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
49prism bt seta eta = dimap (\x -> plus pure id (seta x)) (either id (\x -> fmap bt x)) (right' eta)
52prism bt seta eta = dimap (\x -> plus pure id (seta x)) (either id (\x -> fmap bt x)) (right' eta)
50{-# INLINE prism #-}
53{-# INLINE prism #-}
src/Data/Generics/Product/Subtype.hs+1−1
@@ -40,7 +40,7 @@ import Data.Generics.Product.Internal.Subtype
40import GHC.Generics (Generic (Rep, to, from) )
40import GHC.Generics (Generic (Rep, to, from) )
41import GHC.TypeLits (Symbol, TypeError, ErrorMessage (..))
41import GHC.TypeLits (Symbol, TypeError, ErrorMessage (..))
42import Data.Kind (Type, Constraint)
42import Data.Kind (Type, Constraint)
43−import Data.Generics.Internal.Profunctor.Lens
43+import Data.Generics.Internal.Profunctor.Lens hiding (set)
44
44
45-- $setup
45-- $setup
46-- == /Running example:/
46-- == /Running example:/
src/Data/Generics/Sum/Subtype.hs+1−2
@@ -33,7 +33,6 @@ import Data.Generics.Sum.Internal.Subtype
33import GHC.Generics (Generic (Rep))
33import GHC.Generics (Generic (Rep))
34import Data.Generics.Internal.VL.Prism
34import Data.Generics.Internal.VL.Prism
35import Data.Generics.Internal.Profunctor.Iso
35import Data.Generics.Internal.Profunctor.Iso
36−import Data.Generics.Internal.Profunctor.Prism (prismPRavel)
37
36
38-- $setup
37-- $setup
39-- == /Running example:/
38-- == /Running example:/
@@ -42,7 +41,7 @@ import Data.Generics.Internal.Profunctor.Prism (prismPRavel)
42-- >>> :set -XDataKinds
41-- >>> :set -XDataKinds
43-- >>> :set -XDeriveGeneric
42-- >>> :set -XDeriveGeneric
44-- >>> import GHC.Generics
43-- >>> import GHC.Generics
45−-- >>> :m +Data.Generics.Internal.Lens
44+-- >>> :m +Data.Generics.Internal.VL.Prism
46-- >>> :{
45-- >>> :{
47-- data Animal
46-- data Animal
48-- = Dog Dog
47-- = Dog Dog