diff --git a/Control/Lens/SemiIso.hs b/Control/Lens/SemiIso.hs index 932ca62..c4ca42a 100644 --- a/Control/Lens/SemiIso.hs +++ b/Control/Lens/SemiIso.hs @@ -220,15 +220,15 @@ morphed = iso morph morph constant :: a -> SemiIso' () a constant x = semiIso (\_ -> Right x) (\_ -> Right ()) --- | \-> Always returns the argument. +-- | \-> Filters out all values not equal to the argument. -- --- \<- Filters out all values not equal to the argument. -exact :: Eq a => a -> SemiIso' () a +-- \<- Always returns the argument. +exact :: Eq a => a -> SemiIso' a () exact x = semiIso f g where - f _ = Right x - g y | x == y = Right () + f y | x == y = Right () | otherwise = Left "exact: not equal" + g _ = Right x -- | Like 'filtered' but checks the predicate in both ways. bifiltered :: (a -> Bool) -> SemiIso' a a diff --git a/Data/SemiIsoFunctor.hs b/Data/SemiIsoFunctor.hs index 9a59483..20baf30 100644 --- a/Data/SemiIsoFunctor.hs +++ b/Data/SemiIsoFunctor.hs @@ -161,13 +161,19 @@ class SemiIsoMonad m => SemiIsoFix m where {-# MINIMAL sifix | (=//=) #-} -- | Equivalent of 'sequence'. --- --- Note that it is not possible to write sequence_, because --- you cannot void a SemiIsoFunctor. sisequence :: SemiIsoApply f => [f a] -> f [a] sisequence [] = sipure _Empty sisequence (x:xs) = _Cons /$/ x /*/ sisequence xs +-- | Equivalent of 'sequence_', restricted to units. +sisequence_ :: SemiIsoApply f => [f ()] -> f () +sisequence_ [] = sipure _Empty +sisequence_ (x:xs) = unit /$/ x /*/ sisequence_ xs + -- | Equivalent of 'replicateM'. sireplicate :: SemiIsoApply f => Int -> f a -> f [a] sireplicate n f = sisequence (replicate n f) + +-- | Equivalent of 'replicateM_', restricted to units. +sireplicate_ :: SemiIsoApply f => Int -> f () -> f () +sireplicate_ n f = sisequence_ (replicate n f)