我一直在試驗新的管道-http包,我有一個想法。我有兩個網頁解析器,一個返回頁面中的行項目和另一個數字。當我抓取頁面時,將這些解析器串在一起並同時從相同的字符串生成器獲取它們的結果是非常好的,而不是獲取頁面兩次或者將所有html讀入內存並解析它兩次。將兩個消費者加入到返回多個值的單個消費者中?
換句話說,假設您有兩個消費者:
c1 :: Consumer a m r1
c2 :: Consumer a m r2
是否有可能作出這樣的功能:
combineConsumers :: Consumer a m r1 -> Consumer a m r2 -> Consumer a m (r1, r2)
combineConsumers = undefined
我已經嘗試了一些東西,但我不能想辦法。我明白如果這是不可能的,但它會很方便。
編輯:
對不起原來我是在對管道-attoparsec的假設,因爲我與管道-attoparsec的經驗,使我問錯了問題。當我假設它會返回一個管道消費者時,Pipes-attoparsec將一個attoparsec變成一個管道解析器。這意味着我實際上不能將兩個attoparsec解析器轉換爲接受文本並返回結果的消費者,然後將它們與普通的舊管道生態系統一起使用。我很抱歉,但我不明白管道解析。
即使這對我沒有幫助,但Arthur的答案與我提出問題時的設想非常相似,未來我可能會最終使用他的解決方案。在此期間,我只是要使用導管。
您能鏈接到一個或兩個消費者作爲例子嗎?我熟悉的大部分管道代碼並不使用消費者的基值,並不是用這種方式。另一方面,如果您不使用基礎價值,那麼將兩個消費者拉到一起就是微不足道的。 – Davorak