Hi All,

I was trying to use folds to return the last line of a text file but I 
can't to get the behaviour I want. Specifically it seems to run 
my fold multiple times instead of once over the whole file.

lastline :: IO ()
lastline = runEffect $ (myFold . view T.lines) T.stdin >-> T.stdout
 
myFold :: Monad m => FreeT (Producer Text m) m () -> Producer Text m ()
myFold = folds acc "" extract
acc :: Show a => t -> a -> a
acc _ a = trace ("acc " ++ show a) a
extract :: Show a => a -> a
extract a = trace ("extract " ++ show a) a

When running it with a text file containing
1
2
3

The result I get is:
acc "1"
extract "1"
acc "2"
extract "2"
acc "3"
extract "3"
123

When what I expected was:
acc "1"
acc "2"
acc "3"
extract "3"
3

I'm sure I'm doing something silly and I'm guessing it's in this part: 
"myFold . view T.lines". If someone is able to point me in the right 
direction that would be greatly
appreciated.

cheers
Andrew

-- 
You received this message because you are subscribed to the Google Groups 
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to