Skip to content

Instantly share code, notes, and snippets.

@banacorn
Created November 4, 2020 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banacorn/09ef2906831579116ef147a7ea78ae1e to your computer and use it in GitHub Desktop.
Save banacorn/09ef2906831579116ef147a7ea78ae1e to your computer and use it in GitHub Desktop.
let first p xs =
let length = Array.length xs in
(* mutable aray index *)
let i = ref 0 in
(* there are no loop breaks in OCaml anyway *)
let break = ref false in
while not (!break) && !i < length do
if p (xs.(!i)) then break := true else i := (!i) + 1
done;
!i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment