Skip to content

Instantly share code, notes, and snippets.

@sighingnow

sighingnow/misc.hs

Created Jan 2, 2017
Embed
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