Skip to content

Commit

Permalink
Nitpick: cleaner exception handling in scanf_opt
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectreAAS committed May 24, 2023
1 parent 2c91811 commit 0646e2f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pipeline/cb-schema/schema.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
(* Added because it was introduced to stdlib in 5.0 *)
let sscanf_opt fmt fn ~str = try Some (Scanf.sscanf str fmt fn) with _ -> None
let sscanf_opt fmt fn ~str =
try Some (Scanf.sscanf str fmt fn)
with Scanf.Scan_failure _ | Failure _ | End_of_file -> None

(* Added because it isn't available in reason for some reason *)
let option_value default = function None -> default | Some x -> x

(* Added for convenience *)
let option_or o f = match o with Some x -> x | None -> f ()
let ( >>? ) = option_or

Expand Down

0 comments on commit 0646e2f

Please sign in to comment.