Skip to content

Commit 45106c4

Browse files
committed
Add List.find_index
1 parent 19575a8 commit 45106c4

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
@@ -214,6 +214,14 @@ module List = struct
214214

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

217+
let find_index p =
218+
let rec aux i = function
219+
| [] -> None
220+
| a :: l -> if p a then Some i else aux (i + 1) l
221+
in
222+
aux 0
223+
[@@if ocaml_version < (5, 1, 0)]
224+
217225
let group l ~f =
218226
let rec loop (l : 'a list) (this_group : 'a list) (acc : 'a list list) : 'a list list
219227
=

0 commit comments

Comments
 (0)