filter_map is only available in recent Stdlib

This commit is contained in:
craff 2021-12-19 22:30:18 -10:00
parent 961eb6af65
commit 19ab478d9c
3 changed files with 17 additions and 1 deletions

View file

@ -396,7 +396,7 @@ module Headers = struct
| _ -> None
in
let cookies =
List.filter_map fn_eq (String.split_on_char ';' v) @ cookies
U.filter_map fn_eq (String.split_on_char ';' v) @ cookies
in
(headers, cookies)
end

View file

@ -102,6 +102,18 @@ let split_on_slash s : _ list =
done;
List.rev !l
let filter_map f l =
let rec fn = function
| [] -> []
| x::l ->
begin
match f x with
| None -> fn l
| Some x -> x::fn l
end
in
fn l
(*$= & ~printer:Q.Print.(list string)
["a"; "b"] (split_on_slash "/a/b")
["coucou"; "lol"] (split_on_slash "/coucou/lol")

View file

@ -40,3 +40,7 @@ val pp_date : Format.formatter -> Unix.tm -> unit
for expiration date of cookies.
@since 0.12
*)
val filter_map : ('a -> 'b option) -> 'a list -> 'b list
(** filter_map, now in Stdlib
@since 0.12 *)