Skip to content

Commit

Permalink
Fix: Enum.uniq should use structural comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
murmour committed Nov 23, 2014
1 parent 6aaabc1 commit 927e8c3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/batEnum.ml
Expand Up @@ -833,13 +833,14 @@ let uniq e =
None -> empty ()
| Some first ->
let prev = ref first in
let not_last x = (BatRef.post prev (fun _ -> x)) != x in
let not_last x = (BatRef.post prev (fun _ -> x)) <> x in
let result = filter not_last e in
push result first;
result

(*$T
List.enum [1;1;2;3;3;2] |> uniq |> List.of_enum = [1;2;3;2]
List.enum ["a";"a";"b";"c";"c";"b"] |> uniq |> List.of_enum = ["a";"b";"c";"b"]
*)

let dup t = (t, t.clone())
Expand Down
4 changes: 2 additions & 2 deletions src/batEnum.mli
Expand Up @@ -582,8 +582,8 @@ val merge : ('a -> 'a -> bool) -> 'a t -> 'a t -> 'a t

val uniq : 'a t -> 'a t
(** [uniq e] returns a duplicate of [e] with repeated values
omitted. (similar to unix's [uniq] command)
It uses physical equality to compare consecutive elements. *)
omitted (similar to unix's [uniq] command).
It uses structural equality to compare consecutive elements. *)

val switch : ('a -> bool) -> 'a t -> 'a t * 'a t
(** [switch test enum] splits [enum] into two enums, where the first enum have
Expand Down

0 comments on commit 927e8c3

Please sign in to comment.