Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Last active December 17, 2015 04:18
Show Gist options
  • Save puffnfresh/5549221 to your computer and use it in GitHub Desktop.
Save puffnfresh/5549221 to your computer and use it in GitHub Desktop.
import Data.Foldable
import Data.Monoid
pipeline :: [a -> a] -> a -> a
pipeline = appEndo . getDual . foldMap (Dual . Endo)
main = print $ pipeline [(+1), (*10)] 100
@puffnfresh
Copy link
Author

Output is of course 1010 (not 1001).

@mergeconflict
Copy link

now do pipelineK :: Monad m => [a -> m a] -> a -> m a

...

now do pipelineAllTheThings :: (Foldable f, Monad m) => f (a -> m a) -> a -> m a

@puffnfresh
Copy link
Author

@mergeconflict that is actually a great way of showing that a monad is a monoid in the category of endofunctors. Thanks.

@mergeconflict
Copy link

Yup!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment