@@ -52,7 +52,8 @@ module Control.Lens.SemiIso (
5252 unit,
5353 swapped,
5454 associated,
55− constant
55+ constant,
56+ exact
5657 ) where
5758
5859import Control.Lens.Internal.SemiIso
@@ -112,12 +113,24 @@ unit = iso (, ()) fst
112113associated :: Iso' (a, (b, c)) ((a, b), c)
113114associated = iso (\(a, (b, c)) -> ((a, b), c)) (\((a, b), c) -> (a, (b, c)))
114115
116+-- | \-> Always returns the argument.
117+--
118+-- \<- Maps everything to a @()@.
119+--
120+-- Note that this isn't an @Iso'@ because
121+--
122+-- > unapply (constant x) >=> apply (constant x) /= id
123+--
124+-- But SemiIso laws do hold.
125+constant :: a -> SemiIso' () a
126+constant x = semiIso (\_ -> Right x) (\_ -> Right ())
127+
115128-- | \-> Always returns the argument.
116129--
117130-- \<- Filters out all values not equal to the argument.
118−constant :: Eq a => a -> SemiIso' () a
119−constant x = semiIso f g
131+exact :: Eq a => a -> SemiIso' () a
132+exact x = semiIso f g
120133 where
121134 f _ = Right x
122135 g y | x == y = Right ()
123− | otherwise = Left "constant: not equal"
136+ | otherwise = Left "exact: not equal"