caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dustin Sallings <dustin@spy.net>
To: Caml Mailing List <caml-list@inria.fr>
Subject: [Caml-list] stream conversion
Date: Mon, 8 Dec 2003 23:56:00 -0800	[thread overview]
Message-ID: <2111F26F-2A1D-11D8-8637-000393CB0F1E@spy.net> (raw)


	I have a need to convert a ``string stream'' to a ``char stream.''  
It's a little unclear to me how I'd accomplish this.  This is the best 
I've been able to come up with so far, but I have to imagine there's a 
prettier solution:

let stream_convert source =
     let chunk = ref (Stream.of_string (Stream.next source)) in
     Stream.from (fun x ->
         try
             Stream.empty !chunk;
             try
                 Stream.empty source;
                 None
             with Stream.Failure ->
                 chunk := (Stream.of_string (Stream.next source));
                 Some (Stream.next !chunk)
         with Stream.Failure ->
             Some (Stream.next !chunk)
     )
;;

	Any suggestions?

--
SPY                      My girlfriend asked me which one I like better.
pub  1024/3CAE01D5 1994/11/03 Dustin Sallings <dustin@spy.net>
|    Key fingerprint =  87 02 57 08 02 D0 DA D6  C8 0F 3E 65 51 98 D8 BE
L_______________________ I hope the answer won't upset her. ____________

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


             reply	other threads:[~2003-12-09  7:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-09  7:56 Dustin Sallings [this message]
2003-12-09 12:08 ` Remi Vanicat
2003-12-09 16:58   ` Jean-Baptiste Rouquier
2003-12-09 17:25     ` brogoff
2003-12-09 17:40       ` Jean-Baptiste Rouquier
2003-12-09 18:30       ` Tim Freeman
2003-12-16 22:42         ` Damien Doligez
2003-12-09 19:13     ` Dustin Sallings
2003-12-09 19:15   ` Dustin Sallings
2003-12-10  1:09 ` Nicolas Cannasse

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=2111F26F-2A1D-11D8-8637-000393CB0F1E@spy.net \
    --to=dustin@spy.net \
    --cc=caml-list@inria.fr \
    /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).