git.iko.soy/semi-iso-optics
on master help sign in
Reverse 'exact' to better match sipure and common use cases. Add sireplicate_ and sisequence_.
commita7986cc9692dedd0068a9ebe391a79ba75a74b49 authorPaweł Nowak <pawel834@gmail.com> dateTue 25 Nov 2014, 22:37 (12 years ago) parent2fb082c
2 files changed+14−8
Control/Lens/SemiIso.hs+5−5 Data/SemiIsoFunctor.hs+9−3
Control/Lens/SemiIso.hs+5−5
@@ -220,15 +220,15 @@ morphed = iso morph morph
220220constant :: a -> SemiIso' () a
221221constant x = semiIso (\_ -> Right x) (\_ -> Right ())
222222
223−-- | \-> Always returns the argument.
223+-- | \-> Filters out all values not equal to the argument.
224224--
225−-- \<- Filters out all values not equal to the argument.
226−exact :: Eq a => a -> SemiIso' () a
225+-- \<- Always returns the argument.
226+exact :: Eq a => a -> SemiIso' a ()
227227exact x = semiIso f g
228228 where
229− f _ = Right x
230− g y | x == y = Right ()
229+ f y | x == y = Right ()
231230 | otherwise = Left "exact: not equal"
231+ g _ = Right x
232232
233233-- | Like 'filtered' but checks the predicate in both ways.
234234bifiltered :: (a -> Bool) -> SemiIso' a a
Data/SemiIsoFunctor.hs+9−3
@@ -161,13 +161,19 @@ class SemiIsoMonad m => SemiIsoFix m where
161161 {-# MINIMAL sifix | (=//=) #-}
162162
163163-- | Equivalent of 'sequence'.
164−--
165−-- Note that it is not possible to write sequence_, because
166−-- you cannot void a SemiIsoFunctor.
167164sisequence :: SemiIsoApply f => [f a] -> f [a]
168165sisequence [] = sipure _Empty
169166sisequence (x:xs) = _Cons /$/ x /*/ sisequence xs
170167
168+-- | Equivalent of 'sequence_', restricted to units.
169+sisequence_ :: SemiIsoApply f => [f ()] -> f ()
170+sisequence_ [] = sipure _Empty
171+sisequence_ (x:xs) = unit /$/ x /*/ sisequence_ xs
172+
171173-- | Equivalent of 'replicateM'.
172174sireplicate :: SemiIsoApply f => Int -> f a -> f [a]
173175sireplicate n f = sisequence (replicate n f)
176+
177+-- | Equivalent of 'replicateM_', restricted to units.
178+sireplicate_ :: SemiIsoApply f => Int -> f () -> f ()
179+sireplicate_ n f = sisequence_ (replicate n f)