Skip to content

Commit 2411dc8

Browse files
committed
add Ext_list.find_def
1 parent f36ac63 commit 2411dc8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

jscomp/ext/ext_list.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,13 @@ let rec find_opt xs p =
583583
| Some _ as v -> v
584584
| None -> find_opt l p
585585

586-
586+
let rec find_def xs p def =
587+
match xs with
588+
| [] -> def
589+
| x::l ->
590+
match p x with
591+
| Some v -> v
592+
| None -> find_def l p def
587593

588594
let rec split_map l f =
589595
match l with

jscomp/ext/ext_list.mli

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,13 @@ val find_opt :
259259
('a -> 'b option) ->
260260
'b option
261261

262+
val find_def :
263+
'a list ->
264+
('a -> 'b option) ->
265+
'b ->
266+
'b
262267

268+
263269
val rev_iter :
264270
'a list ->
265271
('a -> unit) ->

0 commit comments

Comments
 (0)