Permalink
Browse files

WIP: make the producers consume the input iteratively.

  • Loading branch information...
rizo committed Aug 22, 2015
1 parent ca6d050 commit 6588c1a42caf2c53b0c3c5f5fd46cc2096f2dc71
Showing with 358 additions and 29 deletions.
  1. +14 −0 NOTES.md
  2. +19 −0 src/iter.ml
  3. +283 −29 src/pipes.ml
  4. +42 −0 src/simple_core.ml
View
@@ -0,0 +1,14 @@
Requirements
------------
- Iterate over values within a structure, or produced by a computation.
- Cleanup resources involved in that computation once they are no longer needed.
- Composable processing, forming a pipeline from the initial source to a final sink.
- Simple model that can be easily understood.
- No-API function definition.
- Good error handling.
- Excellent performance.
- Work on existing opaque types.
- Concurrent execution.
View
@@ -85,6 +85,12 @@ let (>=>) e1 e2 : ('a, 'b) enum =
let (=>) f x = f x
module Syntax = struct
let (>=>) = (>=>)
let (=>) = (=>)
end
let rec fmap f = function
| Yield (x, input) -> Yield (f x, input)
| Await k -> Await (fun input -> fmap f (k input))
@@ -216,6 +222,19 @@ let rec enum_list xs iter =
| Await k, x::xs' -> enum_list xs' (k (Input.Item x))
| _-> iter
let enum_channel chan iter =
let rec step iter =
match iter with
| Yield _ | Error _ -> iter
| Await k ->
try
let x = input_line chan in
step (k (Input.Item x))
with
End_of_file -> iter
in
step iter
let check_done f iter =
match iter with
| Yield _ -> iter
Oops, something went wrong.

0 comments on commit 6588c1a

Please sign in to comment.