(A:
sig
type t
type character
val empty : t
val length : t -> int
val sub_exn : t -> index:int -> length:int -> t
end) = struct
let split_at t ~index =
let l = A.length t in
if index < 0 then (A.empty, t)
else if index >= l then (t, A.empty)
else (A.sub_exn t ~index:0 ~length:index),
(A.sub_exn t ~index:index ~length:(l - index))
let take t ~index =
let l = A.length t in
if index < 0 then A.empty
else if index >= l then t
else A.sub_exn t ~index:0 ~length:index
let drop t ~index =
let l = A.length t in
if index < 0 then t
else if index >= l then A.empty
else (A.sub_exn t ~index:index ~length:(l - index))
end