Skip to content

Instantly share code, notes, and snippets.

@sighingnow
Created January 2, 2017 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sighingnow/1fccd56ffc963a11d68b668c1bd53daa to your computer and use it in GitHub Desktop.
Save sighingnow/1fccd56ffc963a11d68b668c1bd53daa to your computer and use it in GitHub Desktop.
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