File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,17 @@ let swap a b =
3232 a := ! b;
3333 b := x
3434
35+ let protect r x f =
36+ let old = ! r in
37+ r := x;
38+ try
39+ let res = f () in
40+ r := old;
41+ res
42+ with e ->
43+ r := old;
44+ raise e
45+
3546let to_list r = [ ! r ]
3647let to_iter r yield = yield ! r
3748let pp pp_x out r = pp_x out ! r
Original file line number Diff line number Diff line change @@ -33,6 +33,11 @@ val swap : 'a t -> 'a t -> unit
3333(* * [swap t1 t2] puts [!t2] in [t1] and [!t1] in [t2].
3434 @since 1.4 *)
3535
36+ val protect : 'a t -> 'a -> (unit -> 'b ) -> 'b
37+ (* * [protect r x f] sets [r := x]; calls [f()]; restores [r] to its old value;
38+ and returns the result of [f()].
39+ @since NEXT_RELEASE *)
40+
3641val compare : 'a ord -> 'a t ord
3742val equal : 'a eq -> 'a t eq
3843val to_list : 'a t -> 'a list
You can’t perform that action at this time.
0 commit comments