[auto
ekmett@gmail.com**20090330000017] {
hunk ./doc/html/monoids/Data-Monoid-Combinators.html 450
+>filterWith :: (Generator c, Reducer (Elem c) m) => (m -> n) -> (Elem c -> Bool) -> c -> n
filterWithfilterWith | filterWith | Data.Monoid.Combinators | , find
- , sum
- , product
- , notElem
-
- , repeat
- , replicate
- , cycle
-
- , prop_replicate_right_distributive
- ) where
-
-import Prelude hiding (mapM_, any, elem, filter, concatMap, and, or, all, sum, product, notElem, replicate, cycle, repeat)
-import Control.Applicative
-import Control.Monad (MonadPlus)
-import Data.Monoid.Generator
-import Data.Monoid.Applicative
-import Data.Monoid.Self
-import Data.Monoid.Monad
-import Test.QuickCheck
-
-
-
-
-
-
-traverse_ :: (Generator c, Applicative f) => (Elem c -> f b) -> c -> f ()
-traverse_ = mapReduceWith getTraversal
-
-
-
-
-
-
-
-for_ :: (Generator c, Applicative f) => c -> (Elem c -> f b) -> f ()
-for_ = flip traverse_
-
-
-
-
-
-
-
-asum :: (Generator c, Alternative f, f a ~ Elem c) => c -> f a
-asum = reduceWith getAlt
-
-
-
-
-
-
-
-mapM_ :: (Generator c, Monad m) => (Elem c -> m b) -> c -> m ()
-mapM_ = mapReduceWith getAction
-
-
-
-
-
-
-
-forM_ :: (Generator c, Monad m) => c -> (Elem c -> m b) -> m ()
-forM_ = flip mapM_
-
-
-
-
-
-
-
-msum :: (Generator c, MonadPlus m, m a ~ Elem c) => c -> m a
-msum = reduceWith getMonadSum
-
-
-
-
-
-
-
-foldMap :: (Monoid m, Generator c) => (Elem c -> m) -> c -> m
-foldMap = mapReduceWith getSelf
-
-
-
-concatMap :: Generator c => (Elem c -> [b]) -> c -> [b]
-concatMap = foldMap
-
-
-
-
-
-
-
-fold :: (Monoid m, Generator c, Elem c ~ m) => c -> m
-fold = reduceWith getSelf
-
-
-
-toList :: Generator c => c -> [Elem c]
-toList = reduce
-
-
-
-
-
-
-
-and :: (Generator c, Elem c ~ Bool) => c -> Bool
-and = reduceWith getAll
-
-
-
-
-
-
-
-or :: (Generator c, Elem c ~ Bool) => c -> Bool
-or = reduceWith getAny
-
-
-
-
-
-
-
-any :: Generator c => (Elem c -> Bool) -> c -> Bool
-any = mapReduceWith getAny
-
-
-
-
-
-
-
-all :: Generator c => (Elem c -> Bool) -> c -> Bool
-all = mapReduceWith getAll
-
-
-
-
-
-
-
-sum :: (Generator c, Num (Elem c)) => c -> Elem c
-sum = reduceWith getSum
-
-
-
-
-
-
-
-product :: (Generator c, Num (Elem c)) => c -> Elem c
-product = reduceWith getProduct
-
-
-
-elem :: (Generator c, Eq (Elem c)) => Elem c -> c -> Bool
-elem = any . (==)
-
-
-
-notElem :: (Generator c, Eq (Elem c)) => Elem c -> c -> Bool
-notElem x = not . elem x
-
-
-
-filter :: (Generator c, Elem c `Reducer` m) => (Elem c -> Bool) -> c -> m
-filter p = foldMap f where
- f x | p x = unit x
- | otherwise = mempty
-
-
-filterWith :: (Generator c, Elem c `Reducer` m) => (m -> n) -> (Elem c -> Bool) -> c -> n
-filterWith f p = f . filter p
-
-
-
-
-
-
-
-find :: Generator c => (Elem c -> Bool) -> c -> Maybe (Elem c)
-find = filterWith getFirst
-
-
-
-
-replicate :: (Monoid m, Integral n) => m -> n -> m
-replicate x0 y0
- | y0 < 0 = mempty
- | y0 == 0 = mempty
- | otherwise = f x0 y0
- where
- f x y
- | even y = f (x `mappend` x) (y `quot` 2)
- | y == 1 = x
- | otherwise = g (x `mappend` x) ((y 1) `quot` 2) x
- g x y z
- | even y = g (x `mappend` x) (y `quot` 2) z
- | y == 1 = x `mappend` z
- | otherwise = g (x `mappend` x) ((y 1) `quot` 2) (x `mappend` z)
-
-
-
-cycle :: Monoid m => m -> m
-cycle xs = xs' where xs' = xs `mappend` xs'
-
-
-repeat :: (e `Reducer` m) => e -> m
-repeat x = xs where xs = cons x xs
-
-prop_replicate_right_distributive :: (Eq m, Monoid m, Arbitrary m, Integral n) => m -> n -> n -> Bool
-prop_replicate_right_distributive m x y
- = replicate m (x + y) == replicate m x `mappend` replicate m y
+ , filterWith
+ , find
+ , sum
+ , product
+ , notElem
+
+ , repeat
+ , replicate
+ , cycle
+
+ , prop_replicate_right_distributive
+ ) where
+
+import Prelude hiding (mapM_, any, elem, filter, concatMap, and, or, all, sum, product, notElem, replicate, cycle, repeat)
+import Control.Applicative
+import Control.Monad (MonadPlus)
+import Data.Monoid.Generator
+import Data.Monoid.Applicative
+import Data.Monoid.Self
+import Data.Monoid.Monad
+import Test.QuickCheck
+
+
+
+
+
+
+traverse_ :: (Generator c, Applicative f) => (Elem c -> f b) -> c -> f ()
+traverse_ = mapReduceWith getTraversal
+
+
+
+
+
+
+
+for_ :: (Generator c, Applicative f) => c -> (Elem c -> f b) -> f ()
+for_ = flip traverse_
+
+
+
+
+
+
+
+asum :: (Generator c, Alternative f, f a ~ Elem c) => c -> f a
+asum = reduceWith getAlt
+
+
+
+
+
+
+
+mapM_ :: (Generator c, Monad m) => (Elem c -> m b) -> c -> m ()
+mapM_ = mapReduceWith getAction
+
+
+
+
+
+
+
+forM_ :: (Generator c, Monad m) => c -> (Elem c -> m b) -> m ()
+forM_ = flip mapM_
+
+
+
+
+
+
+
+msum :: (Generator c, MonadPlus m, m a ~ Elem c) => c -> m a
+msum = reduceWith getMonadSum
+
+
+
+
+
+
+
+foldMap :: (Monoid m, Generator c) => (Elem c -> m) -> c -> m
+foldMap = mapReduceWith getSelf
+
+
+
+concatMap :: Generator c => (Elem c -> [b]) -> c -> [b]
+concatMap = foldMap
+
+
+
+
+
+
+
+fold :: (Monoid m, Generator c, Elem c ~ m) => c -> m
+fold = reduceWith getSelf
+
+
+
+toList :: Generator c => c -> [Elem c]
+toList = reduce
+
+
+
+
+
+
+
+and :: (Generator c, Elem c ~ Bool) => c -> Bool
+and = reduceWith getAll
+
+
+
+
+
+
+
+or :: (Generator c, Elem c ~ Bool) => c -> Bool
+or = reduceWith getAny
+
+
+
+
+
+
+
+any :: Generator c => (Elem c -> Bool) -> c -> Bool
+any = mapReduceWith getAny
+
+
+
+
+
+
+
+all :: Generator c => (Elem c -> Bool) -> c -> Bool
+all = mapReduceWith getAll
+
+
+
+
+
+
+
+sum :: (Generator c, Num (Elem c)) => c -> Elem c
+sum = reduceWith getSum
+
+
+
+
+
+
+
+product :: (Generator c, Num (Elem c)) => c -> Elem c
+product = reduceWith getProduct
+
+
+
+elem :: (Generator c, Eq (Elem c)) => Elem c -> c -> Bool
+elem = any . (==)
+
+
+
+notElem :: (Generator c, Eq (Elem c)) => Elem c -> c -> Bool
+notElem x = not . elem x
+
+
+
+filter :: (Generator c, Elem c `Reducer` m) => (Elem c -> Bool) -> c -> m
+filter p = foldMap f where
+ f x | p x = unit x
+ | otherwise = mempty
+
+
+filterWith :: (Generator c, Elem c `Reducer` m) => (m -> n) -> (Elem c -> Bool) -> c -> n
+filterWith f p = f . filter p
+
+
+
+
+
+
+
+find :: Generator c => (Elem c -> Bool) -> c -> Maybe (Elem c)
+find = filterWith getFirst
+
+
+
+
+replicate :: (Monoid m, Integral n) => m -> n -> m
+replicate x0 y0
+ | y0 < 0 = mempty
+ | y0 == 0 = mempty
+ | otherwise = f x0 y0
+ where
+ f x y
+ | even y = f (x `mappend` x) (y `quot` 2)
+ | y == 1 = x
+ | otherwise = g (x `mappend` x) ((y 1) `quot` 2) x
+ g x y z
+ | even y = g (x `mappend` x) (y `quot` 2) z
+ | y == 1 = x `mappend` z
+ | otherwise = g (x `mappend` x) ((y 1) `quot` 2) (x `mappend` z)
+
+
+
+cycle :: Monoid m => m -> m
+cycle xs = xs' where xs' = xs `mappend` xs'
+
+
+repeat :: (e `Reducer` m) => e -> m
+repeat x = xs where xs = cons x xs
+
+prop_replicate_right_distributive :: (Eq m, Monoid m, Arbitrary m, Integral n) => m -> n -> n -> Bool
+prop_replicate_right_distributive m x y
+ = replicate m (x + y) == replicate m x `mappend` replicate m y
}
|