Skip to content

Add forUntil family #19

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

chris-martin
Copy link

These loops specifically address the pattern seen in Data.ByteString.hGet and Data.Text.IO.hGetChunk - these functions read a chunk of input from a handle and return an empty string when the end of the input is readed.

For example, a simple "cat" program might look like this:

import Control.Monad.Loops
import System.IO
import qualified Data.Text as T
import qualified Data.Text.IO as T

main = 
main =
  do
    [path] <- getArgs
    withFile path ReadMode $ \h ->
        forUntil_ (T.hGetChunk h) T.null $ \chunk ->
            T.putStr chunk

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant