let filter_map ?(from=0) ?length s ~f =
let length_of_s = S.length s in
let from, length = resize_from_length ~from ?length ~length_of_s in
if length = 0 then empty
else begin
let res = ref [] in
for i = length - 1 downto 0 do
match f (get_exn s (i + from)) with
| Some c -> res := c :: !res
| None -> ()
done;
of_character_list !res
end