I'm trying to understand pipes 4.0, and want to convert some conduit code. Suppose I have a stream of Int
s, and I'd like to skip the first five, then get the sum of the following 5. Using plain lists, this would be:
sum . take 5 . drop 5
In conduit, this would be:
drop 5
isolate 5 =$ fold (+) 0
Or as a complete program:
import Data.Conduit
import Data.Conduit.List (drop, isolate, fold)
import Prelude hiding (drop)
main :: IO ()
main = do
res <- mapM_ yield [1..20] $$ do
drop 5
isolate 5 =$ fold (+) 0
print res
However, I'm not quite certain how to do this with pipes.
fold
type in pipes is significantly different than the type in conduit, which is where the confusion comes from. – Carrico