Skip to content

Instantly share code, notes, and snippets.

@m-alvarez
Created May 12, 2017 16:15
Show Gist options
  • Save m-alvarez/e3095ec397c59d4dd46c1ae89ef00b91 to your computer and use it in GitHub Desktop.
Save m-alvarez/e3095ec397c59d4dd46c1ae89ef00b91 to your computer and use it in GitHub Desktop.
exception Found_element of int
let find_first (p : int -> bool) (s : int Stream.t) =
try (
Stream.iter (fun elt -> if p elt then raise (Found_element elt)) s;
None
)
with
Found_element elt -> Some elt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment