Skip to content

Instantly share code, notes, and snippets.

@SteveGilham
Created April 26, 2015 14:15
Show Gist options
  • Save SteveGilham/b882202f5682682e4541 to your computer and use it in GitHub Desktop.
Save SteveGilham/b882202f5682682e4541 to your computer and use it in GitHub Desktop.
Parse repeating elements (continuation based)
let rec ( ^* ) (generator: ('x option -> continuation) -> continuation, test)
(consumer: 'x list -> 'x option -> continuation) =
generator (function Some x -> if test x
then (generator, test) ^* (fun l -> consumer(x::l))
else consumer [] (Some x)
| None -> consumer [] None);;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment