let sub t ~index ~length =
let r = ref [] in
let c = ref 0 in
try
List.iteri t ~f:(fun i a ->
if i >= index + length then raise Not_found;
if index <= i then (
r:= a :: !r;
incr c;
);
);
if !c = length then Some (List.rev !r) else None
with
| Not_found -> Some (List.rev !r)