Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6150901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:41:21+00:00 2026-05-23T19:41:21+00:00

Earlier today I wrote a small test app for iteratees that composed an iteratee

  • 0

Earlier today I wrote a small test app for iteratees that composed an iteratee for writing progress with an iteratee for actually copying data. I wound up with values like these:

-- NOTE: this snippet is with iteratees-0.8.5.0
-- side effect: display progress on stdout
displayProgress :: Iteratee ByteString IO ()

-- side effect: copy the bytestrings of Iteratee to Handle
fileSink :: Handle -> Iteratee ByteString IO ()

writeAndDisplayProgress :: Handle -> Iteratee ByteString IO ()
writeAndDisplayProgress handle = sequence_ [fileSink handle, displayProgress]

In looking at the enumerator library, I don’t see an analog of sequence_ or enumWith. All I want to do is compose two iteratees so they act as one. I could discard the result (it’s going to be () anyway) or keep it, I don’t care. (&&&) from Control.Arrow is what I want, only for iteratees rather than arrows.

I tried these two options:

-- NOTE: this snippet is with enumerator-0.4.10
run_ $ enumFile source $$ sequence_ [iterHandle handle, displayProgress]
run_ $ enumFile source $$ sequence_ [displayProgress, iterHandle handle]

The first one copies the file, but doesn’t show progress; the second one shows progress, but doesn’t copy the file, so obviously the effect of the built-in sequence_ on enumerator’s iteratees is to run the first iteratee until it terminates and then run the other, which is not what I want. I want to be running the iteratees in parallel rather than serially. I feel like I’m missing something obvious, but in reading the wc example for the enumerator library, I see this curious comment:

-- Exactly matching wc's output is too annoying, so this example
-- will just print one line per file, and support counting at most
-- one statistic per run

I wonder if this remark indicates that combining or composing iteratees within the enumerations framework isn’t possible out of the box. What’s the generally-accepted right way to do this?

Edit:

It seems as though there is no built-in way to do this. There’s discussion on the Haskell mailing list about adding combinators like enumSequence and manyToOne but so far, there doesn’t seem to be anything actually in the enumerator package that furnishes this capability.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:41:22+00:00Added an answer on May 23, 2026 at 7:41 pm

    It seems to me like rather than trying to have two Iteratees consume the sequence in parallel, it would be better to feed the stream through an identity Enumeratee that simply counts the bytes passing it.

    Here’s a simple example that copies a file and prints the number of bytes copied after each chunk.

    import System.Environment
    import System.IO
    import Data.Enumerator
    import Data.Enumerator.Binary (enumFile, iterHandle)
    import Data.Enumerator.List (mapAccumM)
    import qualified Data.ByteString as B
    
    printBytes :: Enumeratee B.ByteString B.ByteString IO ()
    printBytes = flip mapAccumM 0 $ \total bytes -> do
        let total' = total + B.length bytes
        print total'
        return (total', bytes)
    
    copyFile s t = withBinaryFile t WriteMode $ \h -> do
        run_ $ (enumFile s $= printBytes) $$ iterHandle h
    
    main = do
        [source, target] <- getArgs
        copyFile source target
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I wrote this question up earlier today but I decided to delete it
I was thinking earlier today about an idea for a small game and stumbled
Earlier today, I decided to start working on a small control panel for administration
I was taken aback earlier today when debugging some code to find that something
Earlier today my Eclipse started to behave strangely. When I change the Google App
Earlier today I added the mongoid gem version '2.0' to an app. Ever since
I registered a domain account as an HTTP SPN earlier today before realising that
I discovered earlier today that the iterators of a boost::circular buffer were not behaving
I asked a question here earlier today and got that fixed, but now I
Earlier today we migrated away from App Profile Pages to the more traditional Pages

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.