git.iko.soy/semi-iso-optics
on master help sign in
Added 'bifiltered' semi-iso.
commita7625c3c3962c169b5f775f898d92c54da9549d4 authorPaweł Nowak <pawel834@gmail.com> dateSun 23 Nov 2014, 14:17 (12 years ago) parent180dcbc
1 file changed+7
Control/Lens/SemiIso.hs+7
Control/Lens/SemiIso.hs+7
@@ -62,6 +62,7 @@ module Control.Lens.SemiIso (
6262 morphed,
6363 constant,
6464 exact,
65+ bifiltered,
6566
6667 -- * Semi-isos for numbers.
6768 _Negative,
@@ -187,6 +188,12 @@ exact x = semiIso f g
187188 g y | x == y = Right ()
188189 | otherwise = Left "exact: not equal"
189190
191+-- | Like 'filtered' but checks the predicate in both ways.
192+bifiltered :: (a -> Bool) -> SemiIso' a a
193+bifiltered p = semiIso check check
194+ where check x | p x = Right x
195+ | otherwise = Left "bifiltered: predicate failed"
196+
190197_Negative :: Num a => SemiIso' a a
191198_Negative = undefined
192199