Skip to content

Commit

Permalink
Removed filter_map
Browse files Browse the repository at this point in the history
  • Loading branch information
pascutto committed Mar 8, 2021
1 parent 6447b94 commit 442789f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
7 changes: 0 additions & 7 deletions bag.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,6 @@ end) = struct
let filter =
M.filter

let filter_map f =
let f x n = match f x n with
| m when m < 0 -> invalid_arg "filter_map"
| 0 -> None
| m -> Some m in
M.filter_map f

let partition =
M.partition

Expand Down
6 changes: 0 additions & 6 deletions bag.mli
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,6 @@ end) : sig
(** [filter p b] returns the bag with all the elements in [b] that satisfy
predicate [p]. Multiplicities are unchanged. *)

val filter_map: (elt -> int -> int) -> t -> t
(** [filter_map f b] applies the function [f] to every element of [b], and
builds a bag from the results. For each element [x] with multiplicity
[m] in the bag [b], [x] has multiplicity [f x m] in the result.
Raises [Invalid_argument] if [f x m < 0]. *)

val partition: (elt -> int -> bool) -> t -> t * t
(** [partition p b] returns a pair of bags [(b1, b2)], where
[b1] contains all the elements of [b] that satisfy the
Expand Down
2 changes: 1 addition & 1 deletion bag.opam
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ homepage: "https://github.com/backtracking/bag"
doc: "https://backtracking.github.io/bag"
bug-reports: "https://github.com/backtracking/bag/issues"
depends: [
"ocaml" { >= "4.11.0" }
"ocaml" { >= "4.07.0" }
"dune" {>= "2.0.0"}
]
build: [
Expand Down
15 changes: 7 additions & 8 deletions test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ let () =
assert (B.elements a = [1,1; 2,2; 3,3]);
assert (B.min_elt a = (1,1));
assert (B.max_elt a = (3,3));
let f _ _ = 1 in
assert (B.cardinal (B.filter_map f a) = 3);
assert (B.cardinal (B.filter_map f b) = 3);
let f _ = 1 in
assert (B.cardinal (B.map f a) = 3);
assert (B.cardinal (B.map f b) = 3);
let e = B.filter (fun x _ -> x mod 2 = 0) a in
assert (B.min_elt e = (2,2));
assert (B.max_elt e = (2,2));
assert (B.choose e = (2,2));
assert (B.cardinal e = 2);
let o =
B.filter_map (fun x m -> if x mod 2 = 1 then 2*m else 0) b in
assert (B.min_elt o = (1,8));
assert (B.max_elt o = (3,12));
assert (B.cardinal o = 20);
B.filter (fun x _ -> x mod 2 = 1) b in
assert (B.min_elt o = (1,4));
assert (B.max_elt o = (3,6));
assert (B.cardinal o = 10);
()

let test n =
Expand Down Expand Up @@ -62,4 +62,3 @@ let test n =

let () =
for n = 0 to 10 do test (10 * n) done

0 comments on commit 442789f

Please sign in to comment.