-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
define generic in
in terms of any
#55669
base: master
Are you sure you want to change the base?
Conversation
big thumbs up to remove special-cased |
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.
LGTM.
This doesn't pertain to the current PR, which merely matches the existing behavior of using But I will gripe that in(item, collection) -> Bool
∈(item, collection) -> Bool
Determine whether an item is in the given collection, in the sense that it is == to one of the values generated by
iterating over the collection. Return a Bool value, except if item is missing or collection contains missing but not
item, in which case missing is returned (three-valued logic (https://en.wikipedia.org/wiki/Three-valued_logic),
matching the behavior of any and ==).
Some collections follow a slightly different definition. For example, Sets check whether the item isequal to one of
the elements; Dicts look for key=>value pairs, and the key is compared using isequal. I find the choice of julia> -0.0 in [+0.0] # debatable, but if I wanted `==` or `a <= b <= c` I probably should have written that
true
julia> NaN in [NaN] # these are `===`
false and think the fact that julia> -0.0 in Set([+0.0])
false
julia> NaN in Set([NaN])
true |
Since that behavior is clearly stated in the docstring, I assume it's the result of a lengthy discussion. Rather than debating it in this PR, it seems more appropriate to discuss it in a separate issue. |
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. |
It's hard for me to interpret the benchmark results. Do they show any problem? |
I think that the current implementation of
x in itr
is identical toany(==(x), itr)
, see below. An added bonus of callingany
is that a more efficient implementation ofany
for a custom type will most likely give an efficient implementation ofin
for that type at the same time.julia/base/reduce.jl
Lines 1220 to 1238 in 3a2a4d8