let index_of_character_reverse t ?from c =
let length_of_t, rev =
let rec loop lgth acc = function
| [] -> (lgth, acc)
| h :: t -> loop (lgth + 1) (h :: acc) t in
loop 0 [] t
in
let from =
match from with
| None -> length_of_t - 1
| Some s when s < 0 -> -1
| Some s when s > length_of_t - 1 -> length_of_t - 1
| Some s -> s
in
match index_of_character rev ~from:(length_of_t - from - 1) c with
| Some c -> Some (length_of_t - c - 1)
| None -> None