-
-
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 pairs(A) = enumerate(A) #34851
Comments
What would be lost it we deprecated |
I don't think that will work.
Furthermore The bottom line is that the semantics of In the case of |
I think map(first, paris(A)) == keys(A)
map(last, paris(A)) == values(A)
collect(values(A)) == [A[k] for k in keys(A)] Clearly, generic iterables cannot support these interfaces. So, I think it's better to define |
I agree that expanding its implementation this way would (partly) define the API. It says that by default, the keys of a set are taken from its property of being ordered. For a singly linked list, as in JuliaCollections/DataStructures.jl#580, collecting the keys and values are each O(n). You might define On the other hand, one could special-case On the other, other hand, it would be interesting to make Finally, I actually favor my original suggestion here of |
As long as the implementation satisfies the API, it is OK to overload the method. So, it is perfectly fine (and arguably preferred) to overload found = findall(f, A)
@assert all(f(A[i]) for i in found)
@assert all(!f(A[i]) for i in setdiff(keys(A), found)) |
This question is independent of the subject of this post. It would better be asked elsewhere. (The behavior you see is documented. Also, try |
Note that |
Yes. This PR is not the correct solution. |
The method for
findall
with no specialization on the collection type isFor a singly-linked list, like
DataStructures.Cons
,findall
fails because there is no methodkeys(::Cons)
. Constructing, say linear indices forCons
requires traversing the list to find it's length; more precisely, I don't see a way around traversal. Writing a fallback methodwould solve the problem for any iterable, including
Cons
. This assumes thatby default the keys for a collection are
1, 2, ...
.In the case of
Cons
, it's possible that traversing twice, preallocating output after the first pass, would be more efficient. I did not try this, but I doubt it is more efficient.See JuliaCollections/DataStructures.jl#580 .
A somewhat related issue: I think the single argument method for
findall
, which is currentlywould be better refactored as
The text was updated successfully, but these errors were encountered: