Skip to content

Instantly share code, notes, and snippets.

@amosr
Created December 1, 2016 20:48
Show Gist options
  • Save amosr/e654a79e814f401d9d4df6201ec23279 to your computer and use it in GitHub Desktop.
Save amosr/e654a79e814f401d9d4df6201ec23279 to your computer and use it in GitHub Desktop.
zip of partition
(* stream example that would require an unbounded buffer *)
(* read some ints from the network or something *)
(* assume this is infinite so can't buffer *)
let long_stream = unfold read_network socket
(* filter into two streams: those above and those below 0 *)
in let bigs = filter (fun x -> x > 0) long_stream
in let smalls = filter (fun x -> x < 0) long_stream
(* zip the two filtered streams together *)
in let join = zip bigs smalls
in join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment