@@ -52,7 +52,8 @@ module Control.Lens.SemiIso (
54 associated,
54 associated,
55− constant
55+ constant,
58import Control.Lens.Internal.SemiIso
59import Control.Lens.Internal.SemiIso
@@ -112,12 +113,24 @@ unit = iso (, ()) fst
112associated :: Iso' (a, (b, c)) ((a, b), c)
113associated :: Iso' (a, (b, c)) ((a, b), c)
113associated = iso (\(a, (b, c)) -> ((a, b), c)) (\((a, b), c) -> (a, (b, c)))
114associated = iso (\(a, (b, c)) -> ((a, b), c)) (\((a, b), c) -> (a, (b, c)))
116+-- | \-> Always returns the argument.
118+-- \<- Maps everything to a @()@.
120+-- Note that this isn't an @Iso'@ because
122+-- > unapply (constant x) >=> apply (constant x) /= id
124+-- But SemiIso laws do hold.
125+constant :: a -> SemiIso' () a
126+constant x = semiIso (\_ -> Right x) (\_ -> Right ())
115-- | \-> Always returns the argument.
128-- | \-> Always returns the argument.
117-- \<- Filters out all values not equal to the argument.
130-- \<- Filters out all values not equal to the argument.
118−constant :: Eq a => a -> SemiIso' () a
131+exact :: Eq a => a -> SemiIso' () a
119−constant x = semiIso f g
132+exact x = semiIso f g
121 f _ = Right x
134 f _ = Right x
122 g y | x == y = Right ()
135 g y | x == y = Right ()
123− | otherwise = Left "constant: not equal"
136+ | otherwise = Left "exact: not equal"