let split_while xs ~f = let rec loop acc = function | hd :: tl when f hd -> loop (hd :: acc) tl | t -> (rev acc, t) in loop [] xs