Skip to content

Commit cc1598d

Browse files
gpetiotjonludlam
authored andcommitted
join_list without exception
1 parent 64b788b commit cc1598d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/compat.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ module Option = struct
22
type 'a t = 'a option = None | Some of 'a
33

44
let is_some = function None -> false | Some _ -> true
5-
6-
let value_exn = function
7-
| None -> failwith "Option.value_exn None"
8-
| Some x -> x
9-
105
let value ~default = function None -> default | Some x -> x
116

127
let join_list l =
13-
if List.for_all is_some l then Some (List.map value_exn l) else None
8+
let rec loop acc = function
9+
| [] -> Some (List.rev acc)
10+
| Some a :: q -> loop (a :: acc) q
11+
| None :: _ -> None
12+
in
13+
loop [] l
1414
end
1515

1616
module Char = struct

0 commit comments

Comments
 (0)