Commit 0db025e5 authored by Andrei Paskevich's avatar Andrei Paskevich

Lists: add map_filter

parent a61bd87a
......@@ -28,6 +28,11 @@ let map_fold_right f l acc =
(fun e (l, acc) -> let e, acc = f e acc in e :: l, acc)
l ([], acc)
let map_filter f l =
List.fold_right
(fun e l -> match f e with Some e -> e :: l | None -> l)
l []
let equal pr l1 l2 =
try List.for_all2 pr l1 l2 with Invalid_argument _ -> false
......
......@@ -20,6 +20,8 @@ val map_fold_left :
val map_fold_right :
('a -> 'acc -> 'b * 'acc) -> 'a list -> 'acc -> 'b list * 'acc
val map_filter : ('a -> 'b option) -> 'a list -> 'b list
val equal : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
val compare : ('a -> 'a -> int) -> 'a list -> 'a list -> int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment