Skip to content

Instantly share code, notes, and snippets.



Created Jan 2, 2017
What would you like to do?
concatMap and filter using Foldable and Traversable.
concatMap :: (Foldable f, Monoid (f b)) => (a -> f b) -> f a -> f b
concatMap = foldMap
filter :: (Applicative f, Foldable f, Monoid (f a)) =>
(a -> Bool) -> f a -> f a
filter p = foldMap (\a -> if p a then pure a else mempty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment