Module Tjr_lib_core.Iter

Various iteration operators

val iter_opt : ('a -> 'a option) -> 'a -> 'a
type ('a, 'b) break_or_cont =
| Break of 'a
| Cont of 'b
val iter_break : ('a -> ('b'a) break_or_cont) -> 'a -> 'b

Iterate until reach break

val iter_k : (k:('a -> 'b) -> 'a -> 'b) -> 'a -> 'b

Essentially the Y combinator; useful for anonymous recursive functions. The k argument is the recursive callExample:

iter_k (fun ~k n -> 
    if n = 0 then 1 else n * k (n-1))