on master help sign in
Implement prism following the either-right invariant
81e7fecMatthew Pickering
src/Data/Generics/Internal/Lens.hs+2−1
@@ -118,7 +118,8 @@ prismE :: (b -> t) -> (s -> Either t a) -> PrismE s t a b
118prismE bt seta = mdimap (liftFun seta) (EitherFun id bt) . mright
118prismE bt seta = mdimap (liftFun seta) (EitherFun id bt) . mright
119
119
120prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
120prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
121−prism bt seta = dimap seta (either pure (fmap bt)) . right'
121+prism bt seta eta = dimap (\x -> plus pure id (seta x)) (either id (\x -> fmap bt x)) (right' eta)
122+{-# INLINE prism #-}
122
123
123-- | A type and its generic representation are isomorphic
124-- | A type and its generic representation are isomorphic
124repIso :: (Generic a, Generic b) => Iso a b (Rep a x) (Rep b x)
125repIso :: (Generic a, Generic b) => Iso a b (Rep a x) (Rep b x)