Question

I am having source crawling some websites and collects items of type Category from them:

catsSource :: Source IO Category

The next step is to write companies collector (items of type Company). Companies collector needs categories: for each Category on input several companies should be produced, one by one. In other word it should "yield" Company, not [Company]. What do I need for this task? Conduit or tricky source? If source, how it should get categories from catsSource? If conduit how it should pass ("yield") company forward when it is found?

To clear my question here is an attempt (not passing type check):

import qualified Data.Conduit.List as CL

companiesFromCategory cat = [Company "foo", Company "bar"]

companies :: Conduit Category IO Company
companies = CL.fold . (CL.map companiesFromCategory)
Was it helpful?

Solution

The solution is to use concatMap:

companies = CL.concatMap companiesFromCategory
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top