let filteri l ~f = List.rev (foldi l ~f:(fun pos acc x -> if f pos x then x :: acc else acc) ~init:[])