let scanl xs ~init ~f =
let current = ref init in
let f i =
if i = 0 then Some init
else (
match next xs with
| Some x ->
current := f !current x ;
Some !current
| None -> None
)
in
from f