-
-
Save little-arhat/896205 to your computer and use it in GitHub Desktop.
possible patch for batStream.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* batStream.ml *) | |
let to_list fl = | |
let buf = ref [] | |
in (iter (fun x -> buf := x :: !buf) fl; List.rev !buf) | |
let to_string fl = | |
let sl = to_list fl in | |
let len = List.length sl in | |
let s = String.create len | |
in (List.iter (let i = ref 0 in fun x -> (s.[!i] <- x; incr i)) sl; s) | |
(* vs *) | |
let to_string ?(len=16) s = | |
let buf = Buffer.create len in | |
let () = iter (fun ch -> Buffer.add_char buf ch) s in | |
Buffer.contents buf | |
(* and more flexible *) | |
let to_string_fmt fmt st = | |
let buf = Buffer.create 16 in | |
let () = Stream.iter (fun it -> | |
Buffer.add_string buf (Printf.sprintf fmt st)) st in | |
Buffer.contents buf | |
let to_string_fun fn st = | |
let buf = Buffer.create 16 in | |
let () = Stream.iter (fun it -> Buffer.add_string buf (fn it)) st in | |
Buffer.contents buf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment