Advertisement
xavierm02

Untitled

Aug 11th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 1.30 KB | None | 0 0
  1. (* ... *)
  2. (* 146 *) (** [apply_enum f x] applies [f] to [x] and converts exceptions
  3. (* 147 *)     [No_more_input] and [Input_closed] to [BatEnum.No_more_elements]*)
  4. (* 148 *) let apply_enum do_close f x =
  5. (* 149 *)   try f x
  6. (* 150 *)   with
  7. (* 151 *)   | No_more_input -> raise BatEnum.No_more_elements
  8. (* 152 *)   | Input_closed  -> do_close := false; raise BatEnum.No_more_elements
  9. (* 153 *)
  10. (* 154 *) (** [close_at_end input e] returns an enumeration which behaves as [e]
  11. (* 155 *)     and has the secondary effect of closing [input] once everything has
  12. (* 156 *)     been read.*)
  13. (* 157 *) let close_at_end do_close (input:input) e =
  14. (* 158 *)   BatEnum.suffix_action (fun () -> if !do_close then close_in input) e
  15. (* 159 *)
  16. (* 160 *) let make_enum f input =
  17. (* 161 *)   let do_close = ref true in
  18. (* 162 *)   close_at_end do_close input (BatEnum.from (fun () -> apply_enum do_close f input))
  19. (* ... *)
  20. (* 482 *)(* make a bunch of char enums by reading buffer_size at a time and
  21. (* 483 *)   concat them all into into one big char enum *)
  22. (* 484 *)let chars_of input =
  23. (* 485 *)  let do_close = ref true in
  24. (* 486 *)  close_at_end do_close input (BatEnum.concat (BatEnum.from (fun () ->
  25. (* 487 *)        apply_enum do_close (fun source -> string_enum (nread source buffer_size)) input)))
  26. (* ... *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement