-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Implement Enum.equal? #978
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👍 We just need to discuss the naming. |
Oh, the build failed. Could you please check? |
Yeah, checking, I ran the tests and it was all green here. |
Oh, I completely forgot about doctests, I have no idea about how it works, any hints? |
|
||
iex> Enum.equal?([], []) | ||
true | ||
iex> Enum.equal?(1 .. 3, 1 .. 3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be it would make sense to add Enum.equal?(1 .. 3, [1 .. 3])
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just in the examples? It should return false, shouldn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant 1..3, [1,2,3]
this way it'll compare if both enums are equal as enums.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sure thing, fixing it.
Yeah, doctests are magic, I forgot to add a case with empty list and non empty iterator and luckily I put it in the examples. |
user=> (= { :a 2 :b 3 } { :b 3 :a 2 })
true I guess |
Yes, Dict.equal? will be fine. My worries are about Enum.equal?. The José Valim |
user=> (= [1 2 3] '(1 2 3))
true Clojure doesn't care. |
@josevalim Do you mean difference in ordering of elements? Or difference in structure? (i think both Enum.equal? and Dict.equal? should ignore structure) |
Yes, structural was not the best choice of word. I should have said Let me give another example: today we have Keyword.equal? that works only Another example of semantical behavior: String.equal?. We could have a Note we already have a strict equal impl, via ==. :) José Valim |
So like an |
Wait on merging this if the naming issue is resolved, I'm adding a version where you can provide a function to compare the elements. |
It compares different kinds of collections based on the elements it would iterate through.
In my case, it would be useful to compare ets tables of ordered set type, it would also be used as fallback in Dict.equal? which I'm going to implement now.