Skip to content

Commit b911ee8

Browse files
committed
Add List.find_index
1 parent 03fc469 commit b911ee8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

compiler/lib/stdlib.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ module List = struct
195195

196196
let append l1 l2 = count_append l1 l2 0 [@@if ocaml_version < (5, 1, 0)]
197197

198+
let find_index p =
199+
let rec aux i = function
200+
| [] -> None
201+
| a :: l -> if p a then Some i else aux (i + 1) l
202+
in
203+
aux 0
204+
[@@if ocaml_version < (5, 1, 0)]
205+
198206
let group l ~f =
199207
let rec loop (l : 'a list) (this_group : 'a list) (acc : 'a list list) : 'a list list
200208
=

0 commit comments

Comments
 (0)