Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

map2

  • Loading branch information...
commit 748d534fa0f0473a77088eb8693a05c7837e6b7c 1 parent 5a368d4
Jake Donham authored
Showing with 31 additions and 2 deletions.
  1. +22 −0 src/froc/froc.ml
  2. +9 −2 src/froc/froc.mli
View
22 src/froc/froc.ml
@@ -143,6 +143,28 @@ let map f t =
end;
rt
+let map2 f t1 t2 =
+ if is_never t1 && is_never t2 then never
+ else
+ let rt, ru = make_event () in
+ let notify = ref false in
+ add_reader2 t1 t2 begin fun () ->
+ if not !notify then notify := true
+ else
+ let r =
+ match read_result t1, read_result t2 with
+ | Fail Unset, _
+ | _, Fail Unset -> None
+ | Fail e, _
+ | _, Fail e -> Some (Fail e)
+ | Value v1, Value v2 ->
+ try Some (Value (f v1 v2)) with e -> Some (Fail e) in
+ match r with
+ | None -> ()
+ | Some r -> write_temp_result ru r
+ end;
+ rt
+
let filter p t =
if is_never t then never
else
View
11 src/froc/froc.mli
@@ -315,8 +315,15 @@ val merge : 'a event list -> 'a event
val map : ('a -> 'b) -> 'a event -> 'b event
(**
- [map f e] is an event that fires [f v] whenever [e] fires
- [v]. The function [f] delimits a dynamic scope governed by [e].
+ [map f e] fires [f v] whenever [e] fires [v]. The function [f]
+ delimits a dynamic scope governed by [e].
+ *)
+
+val map2 : ('a -> 'b -> 'c) -> 'a event -> 'b event -> 'c event
+ (**
+ [map2 f e1 e2] fires [f v1 v2] whenever [e1] and [e2] fire [v1]
+ and [v2] simultaneously. The function [f] delimits a dynamic
+ scope governed by [e1] and [e2].
*)
val filter : ('a -> bool) -> 'a event -> 'a event
Please sign in to comment.
Something went wrong with that request. Please try again.