let iterator t ~collection =
let allref = ref None in
begin fun () ->
begin match !allref with
| None ->
get_all t collection
>>= fun all ->
let a = ref all in
allref := Some a;
return a
| Some l -> return l
end
>>= fun all ->
match !all with
| [] -> return None
| h :: t -> all := t; return (Some h)
end