Skip to content

Commit 113f5b3

Browse files
committed
linear_merge: invalid_arg where applicable; all args non-optional
1 parent d242d12 commit 113f5b3

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Diff for: src/reactiveData.ml

+12-12
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,11 @@ module DataList = struct
215215
let acc = h :: acc in
216216
linear_merge_fwd (i - 1) l ~acc
217217
| [] ->
218-
failwith "linear_merge_fwd"
218+
invalid_arg "invalid index"
219219
else
220220
l, acc
221221

222-
let rec linear_merge ?(acc = []) i0 p l =
222+
let rec linear_merge i0 p l ~acc =
223223
let l, acc =
224224
match p with
225225
| (I (i, _) | R i | U (i, _)) :: _ when i > i0 ->
@@ -229,34 +229,34 @@ module DataList = struct
229229
in
230230
match p, l with
231231
| I (i, x) :: p, _ ->
232-
linear_merge ~acc i p (x :: l)
232+
linear_merge i p (x :: l) ~acc
233233
| R i :: p, _ :: l ->
234-
linear_merge ~acc i p l
234+
linear_merge i p l ~acc
235235
| R _ :: _, [] ->
236-
failwith "ReactiveData.RList.linear_merge: remove from empty"
236+
invalid_arg "merge: invalid index"
237237
| U (i, x) :: p, _ :: l ->
238-
linear_merge ~acc i p (x :: l)
238+
linear_merge i p (x :: l) ~acc
239239
| U (_, _) :: _, [] ->
240-
failwith "ReactiveData.RList.linear_merge: update empty"
240+
invalid_arg "merge: invalid index"
241241
| [], l ->
242242
List.rev_append acc l
243243
| X (_, _) :: _, _ ->
244-
failwith "ReactiveData.RList.linear_merge: X not supported"
244+
failwith "linear_merge: X not supported"
245245

246-
let rec linear_mergeable ?(n = 0) p =
246+
let rec linear_mergeable p ~n =
247247
assert (n >= 0);
248248
match p with
249249
| (I (i, _) | R i | U (i, _)) :: p when i >= n ->
250250
(* negative i's ruled out (among others) *)
251-
linear_mergeable ~n:i p
251+
linear_mergeable p ~n:i
252252
| _ :: _ ->
253253
false
254254
| [] ->
255255
true
256256

257257
let merge p l =
258-
if linear_mergeable p then
259-
linear_merge 0 p l
258+
if linear_mergeable p ~n:0 then
259+
linear_merge 0 p l ~acc:[]
260260
else
261261
List.fold_left (fun l x -> merge_p x l) l p
262262

0 commit comments

Comments
 (0)