git.iko.soy/semi-iso-optics
on master help sign in
Rename "constant" to "exact". Add a real "constant" semiiso.

Bump the version to 0.2.0.0.

commitd1f9df6d895a3e0b2b8dac88fd037348eddc2816 authorPaweł Nowak <pawel834@gmail.com> dateWed 29 Oct 2014, 16:10 (12 years ago) parent16e692f
2 files changed+18−5
Control/Lens/SemiIso.hs+17−4 semi-iso.cabal+1−1
Control/Lens/SemiIso.hs+17−4
@@ -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"
semi-iso.cabal+1−1
@@ -1,5 +1,5 @@
11name: semi-iso
2−version: 0.1.0.0
2+version: 0.2.0.0
33synopsis: Weakened partial isomorphisms that work with lenses.
44description: Semi-isomorphisms are partial isomorphisms with weakened iso laws.
55 And they work with Iso and Prism from @lens@!