-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
added haskey method for tuple #38579
base: master
Are you sure you want to change the base?
Conversation
Hi! I tried to read the error messages from the 2 builds that failed but I couldn't understand if they're related to the changes I did. (I'd suppose they are, but I cannot find the function I defined anywhere. Maybe I should define the types of the function explicitly in order for the method I defined not to be used in other places. |
Note that this definition is far more general than just tuples. @JeffBezanson: are you ok with this kind of highly general fallback definition? |
Hi! If not, I could define it instead as |
No, the builds aren't passing for a variety of unrelated reasons that are being worked on. |
Ok! :) So I'll wait for @JeffBezanson to express his opinion on the typing of the container and maybe update the branch. Does that sound alright? |
Welcome; thanks for making this PR! I think I would rather have a more specific
We should also discuss a bit what |
Hi! Thanks a lot for taking the time to explain what's the deal with the possible problems of having such a general method. I'm not so sure why it could be O(n) (And how would that change with a more specific method).
I tried applying the function to an array and it seems to work; I think I probably don't understand what you meant by that last sentence. |
Some collections allow different keys for the same element, for example
but
The same thing happens with NamedTuples, which allow both integers and symbols. |
Interesting. Then we should also add a method for |
Closing, as this seems stale, though still welcome. Jeff gave good feedback above that this would need to explicitly handle more cases, instead of being a catch-all. |
Hi! I got a little bit confused with the workflow. |
I can reopen this one (until you push a new commit, then github will prohibit reopening), or you can make a new PR and reference this one as the description. Either is great :) |
I'm sorry. This is my first PR so things are a bit new to me. I think reopening this one would be easier, but I didn't understand if I need to push a new commit or if pushing a new commit will make it impossible to reopen it. |
Thanks for reopening the branch. Since v1.6 just came out, it would make sense to pull that first, just to make sure everything still works, right? |
Hi! I have a little question for @JeffBezanson (or anybody else who'd like to help me out) . It might be a bit silly, but this being my first PR I'd rather be sure. I'm trying to implement a method for function haskey(container::Tuple, key::CartesianIndex{1})
@_inline_meta
key[1] ∈ keys(container)
end but when I run
I suppose it's because tuple.jl doesn't know of Thanks in advance! |
I would suggest putting that method after the definition of CartesianIndex, rather than trying to make it work in tuples.jl |
That makes a lot of sense. Thanks! :) Once that's done, I should maybe rebase and squash some commits before pushing it here, right? |
Hi! Thanks in advance :) |
#35516
I added the suggested fallback and some tests to make sure it works with both Int and Float keys.
This is my first PR, so feel free to make any comment you might consider relevant.
I was also very confused about the @_inline_meta macro, but included it since similar functions had it. I tried googling something about it but found very cryptic explanations.
All in all, I hope this is a useful contribution :)