mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 03:35:30 -05:00
CCList.sort_uniq
This commit is contained in:
parent
b521f3af8e
commit
9595ac688c
2 changed files with 16 additions and 0 deletions
|
|
@ -179,6 +179,19 @@ let sorted_merge ?(cmp=Pervasives.compare) l1 l2 =
|
||||||
= [11; 20; 101; 200]
|
= [11; 20; 101; 200]
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
let sort_uniq (type elt) ?(cmp=Pervasives.compare) l =
|
||||||
|
let module S = Set.Make(struct
|
||||||
|
type t = elt
|
||||||
|
let compare = cmp
|
||||||
|
end) in
|
||||||
|
let set = fold_right S.add l S.empty in
|
||||||
|
S.elements set
|
||||||
|
|
||||||
|
(*$T
|
||||||
|
sort_uniq [1;2;5;3;6;1;4;2;3] = [1;2;3;4;5;6]
|
||||||
|
sort_uniq [] = []
|
||||||
|
sort_uniq [10;10;10;10;1;10] = [1;10]
|
||||||
|
*)
|
||||||
|
|
||||||
let take n l =
|
let take n l =
|
||||||
let rec direct i n l = match l with
|
let rec direct i n l = match l with
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,9 @@ val filter_map : ('a -> 'b option) -> 'a t -> 'b t
|
||||||
val sorted_merge : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
|
val sorted_merge : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
|
||||||
(** merges elements from both sorted list, removing duplicates *)
|
(** merges elements from both sorted list, removing duplicates *)
|
||||||
|
|
||||||
|
val sort_uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list
|
||||||
|
(** Sort the list and remove duplicate elements *)
|
||||||
|
|
||||||
(** {2 Indices} *)
|
(** {2 Indices} *)
|
||||||
|
|
||||||
module Idx : sig
|
module Idx : sig
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue