Commits

camlspotter committed 8c6fd54

added with_final

Comments (0)

Files changed (2)

 let try_ignore ~f v = try f v with _ -> ();;
 let try_bool ~f v = try ignore (f v); true with _ -> false
 
+let with_final v f final =
+  match try `Ok (f v) with e -> `Error e with
+  | `Ok res -> final v; res
+  | `Error e -> try_ignore ~f:final v; raise e
+
 let time f v =
   let start = Unix.gettimeofday () in
   let res = f v in
 val try_bool   : f:('a -> 'b) -> 'a -> bool
 (** [true] at success *)
 
+val with_final : 'a -> ('a -> 'b) -> ('a -> unit) -> 'b
+
 (** {6 Imperative operations } *)
 
 val imp : 'a -> ('a ref -> 'b) -> ('a * 'b)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.