-
-
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
findmin with filtered iterators fail #47124
Comments
I'm not sure this is a bug. What would the index of an |
My general expectation is that functions applied on iterators return the same as if applied to the collected versions of the same iterators. At least it would be nice to have a better error message there, if one does not want to introduce that possible source of confusion. |
I interpret this to mean that If we choose not to fix this issue, then we should adjust the docstring to include a similar caveat as |
Doesn't look like iterators have any indices by default: julia> it = Iterators.filter(!=(1), [3,2,1])
Base.Iterators.Filter{Base.Fix2{typeof(!=), Int64}, Vector{Int64}}(Base.Fix2{typeof(!=), Int64}(!=, 1), [3, 2, 1])
julia> eachindex(it)
ERROR: MethodError: no method matching keys(::Base.Iterators.Filter{Base.Fix2{typeof(!=), Int64}, Vector{Int64}}) |
As I understand this was a conscious design decision, see #25999 and #26095 (these were for other Maybe what is missing is an easy way to wrap an iterator in a type that supports julia> Base.pairs(it::Iterators.Enumerate) = Iterators.map(Base.splat(=>), it);
julia> findmin(enumerate(Iterators.filter(!=(1), [3,2,1])))
(2, 2) |
See also #34851 |
Yes. Often It doesn't make sense to me to implement semantics for default keys in some places, but not here. |
I don't think it's right to aim for equivalence of |
I agree. I don't have a clear view of when they are sort of the same. I used "Often" to indicate that I don't claim they are unconditionally equivalent. There are many places, all over the ecosystem, where passing an iterator fails, while passing I haven't seen a concrete example of problems that would arise from being able to do something like Another idea is an entirely new function Hmmm. I'm confused about the current status. If I do |
See: https://discourse.julialang.org/t/findmin-max-and-generators/88473?u=lmiq
Basically, this does not work:
The text was updated successfully, but these errors were encountered: