-
-
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 Base.iterate(::Nothing) = nothing ? #29877
Comments
Well,
|
No, I don't think we should do this. Nothing is not a 0-element iterator, it's nothing.
|
I see a pattern of
If b is the prevalent pattern, then I guess my answer to the HTTP.jl user should be that they should not pass |
Yes B is the intended use. Unions with Nothing are like Option types; you're supposed to check before using the value. However it would be perfectly reasonable for HTTP to support |
Currently we have this: const nobody = UInt8[]
function request(method, url, h=Header[], b=nobody;
headers=h, body=b, query=nothing, kw...)::Response Would you suggest that it is better to say: function request(method, url, h=Header[], b=nothing;
headers=h, body=b, query=nothing, kw...)::Response (and add the check for |
Does |
Duplicate of #26695. |
UInt8[] behaves the way I want it to. |
Answer: "Because |
You can also do |
The real issue here is that there's no way for us to define |
And the default error message is not good because it looks like that it might as well have been a bug in HTTP? |
The doc says:
The remaining question is simply: (to conform to the principle of least surprise for users) should the interface accept
The reason for filing this issue was that if Julia's |
No, I think the error message is fine as it is. If we put too many restrictive preconditions on things we'll loose the benefits of being able to keep things loosely coupled by implementing only as much duck-ness as is needed in a particular situation. I recall some particularly painful experiences in other languages where some API wants a |
This is a very good question, and a bit tricky. Allowing |
I'm happy to stick with the current API where you can pass |
Would it make sense to define
Base.iterate(::Nothing) = nothing
?HTTP.jl has a generic interface that accepts anything iterable.
A user has reported
method matching iterate(::Nothing)
when they passednothing
.It seems that
eltype
is already defined.But,
HasEltype
,HasShape
andHasLength
are not.The text was updated successfully, but these errors were encountered: