Anonymous avatar Anonymous committed 2f41183

Cd_Array: index_opt

Comments (0)

Files changed (1)

           else inner [(f arr1.(i) arr2.(i)) :: acc] (i - 1)
     ;
 
+    value index_opt
+     : ('a -> bool) -> array 'a -> option int
+     = fun pred arr ->
+         let len = Array.length arr in
+         loop 0
+         where rec loop i =
+           if i = len
+           then
+             None
+           else
+             if pred arr.(i)
+             then Some i
+             else loop (i + 1)
+    ;
+
     value dump ~t arr =
       arr
       |> map_to_list t#show
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.