This past weekend I had reason to use conduit to process the contents of a large number of files as a single stream. Fortunately conduit supplies a Monoid instance. Monoid allows us to append things together. This example is very short but very useful. This little code block creates many sources and collapses them together into a single source that will be ordered by the file name. Quite cool.
let source = foldl1 (<>) $ map sourceFile $ sort files runResourceT $ do source $$ someConduit chain ...
Thanks to drb226 for his suggestions.
So obviously there are other ways of writing this. Tekmo suggested using the >> binad and discard operator which would make our code look like:
let source = foldl1 (<>) $ map sourceFile $ sort files
Sjoerd Visscher suggested using foldMap from Data.Foldable. So that gives us:
let source = foldMap sourceFile $ sort files
Thanks for the feedback.