on master help sign in
Implement prism following the either-right invariant
commit81e7fec6088f516b24367965bb031586ec43034a authorMatthew Pickering <matthewtpickering@gmail.com> dateTue 16 Jan 2018, 13:59 (9 years ago) parent6eb09a5
1 file changed+2−1
src/Data/Generics/Internal/Lens.hs+2−1
src/Data/Generics/Internal/Lens.hs+2−1
@@ -118,7 +118,8 @@ prismE :: (b -> t) -> (s -> Either t a) -> PrismE s t a b
118118prismE bt seta = mdimap (liftFun seta) (EitherFun id bt) . mright
119119
120120prism :: (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 #-}
122123
123124-- | A type and its generic representation are isomorphic
124125repIso :: (Generic a, Generic b) => Iso a b (Rep a x) (Rep b x)