caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yaron Minsky <yminsky@janestreet.com>
To: Jon Kleiser <jon.kleiser@ceres.no>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Is there a way to abort Stream.iter ?
Date: Sat, 13 May 2017 08:24:17 -0400	[thread overview]
Message-ID: <CACLX4jSUQny6Bx3_3LRh2WGYsVLMkXfgaVXzC6DvzCbANMzCmQ@mail.gmail.com> (raw)
In-Reply-To: <2490F692-502C-408E-9E60-30216557DF15@mail.uio.no>

First of all, you should probably use a Pipe.t rather than a Stream.t.
Streams don't provide you with a way of pushing back, meaning the
process that's filling data into the Stream won't slow down if you're
slow in draining data from it. Pipes give you a mechanism for doing
this, in that a Pipe has a bounded amount of slack.

For pipes, when I want to control the exit time, I'll typically do a
recursive loop using Pipe.read or Pipe.read'. You can do something
similar with streams.

y

On Fri, May 12, 2017 at 10:34 AM, Jon Kleiser <jon.kleiser@ceres.no> wrote:
> In my little program here <http://folk.uio.no/jkleiser/ocaml/read_vec.ml> I’m reading and processing a text file by doing this:
>
> let process_lines lines =
>   let start_time = Sys.time () in
>   Stream.iter process_line lines;
>   let finish_time = Sys.time () in
>   Printf.printf "\nTime used: %f secs\n" (finish_time -. start_time)
>
> . . . where the ‘lines’ input is coming from ‘(line_stream_of_channel in_channel)’.
>
> Is there a way to abort the Stream.iter processing based on some condition detected by the ‘process_line’ function? Could it be done by throwing an exception? Maybe I should use something else than Stream.iter ?
>
> /Jon
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

  reply	other threads:[~2017-05-13 12:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-12 14:34 Jon Kleiser
2017-05-13 12:24 ` Yaron Minsky [this message]
2017-05-13 12:25   ` Yaron Minsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACLX4jSUQny6Bx3_3LRh2WGYsVLMkXfgaVXzC6DvzCbANMzCmQ@mail.gmail.com \
    --to=yminsky@janestreet.com \
    --cc=caml-list@inria.fr \
    --cc=jon.kleiser@ceres.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).