git.iko.soy/semi-iso-optics
on master help sign in
Finish _Negative.
82588b5Paweł Nowak
Control/Lens/SemiIso.hs+10−6
@@ -66,7 +66,6 @@ module Control.Lens.SemiIso (
66
66
67 -- * Semi-isos for numbers.
67 -- * Semi-isos for numbers.
68 _Negative,
68 _Negative,
69− _Positive,
70
69
71 -- * Transforming semi-isos.
70 -- * Transforming semi-isos.
72 rev,
71 rev,
@@ -194,11 +193,16 @@ bifiltered p = semiIso check check
194 where check x | p x = Right x
193 where check x | p x = Right x
195 | otherwise = Left "bifiltered: predicate failed"
194 | otherwise = Left "bifiltered: predicate failed"
196
195
196+-- | \-> Matches only negative numbers, turns it into a positive one.
197+--
198+-- \<- Matches only positive numbers, turns it into a negative one.
197−_Negative :: Num a => SemiIso' a a
199+_Negative :: Real a => SemiIso' a a
198−_Negative = undefined
200+_Negative = semiIso f g
199−
201+ where
200−_Positive :: Num a => SemiIso' a a
202+ f x | x < 0 = Right (-x)
201−_Positive = undefined
203+ | otherwise = Left "_Negative: apply expected a negative number"
204+ g x | x >= 0 = Right (-x)
205+ | otherwise = Left "_Negative: unapply expected a positive number"
202
206
203-- | Reverses a 'SemiIso'.
207-- | Reverses a 'SemiIso'.
204rev :: ASemiIso s t a b -> SemiIso b a t s
208rev :: ASemiIso s t a b -> SemiIso b a t s