-
-
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
findfirst
on dictionaries returns ambiguous result
#29565
Comments
Yes, that's been discussed before. We didn't change the default behavior since it would be inconvenient for the (very common) cases where you know the keys cannot be |
I think this is too ad hoc. It would work in a scripting language where it's assumed that the person calling Calling Cautioning against use of i, _... = findall(f, x) for an error or ixs = findall(f, x)
isempty(ixs) ? nothing : Some(first(ixs)) seems like the safest approach. |
Maybe this is a more productive idea: can we throw an error if the found index is |
Another idea for 1.x: add a This isn't a good solution for 2.0 because it tempts library authors to assume |
I was playing again with dictionaries and similar containers that may have any
keytype
(includingAny
) and was surprised by the newfindfirst
API. Take the following exampleIn the above, the first two cases are completely ambiguous! It would be nice if I could distinguish the case that the key of the found item was was
nothing
, or ifnothing
was found. In this case, I wonder if it would be more natural for this API to return a type that you unwrap (likeSome
or the oldNullable
or perhaps even something like a vector of length 0 or 1 which actually makes it quite compatible with the results offindall
)?(While some might consider the above example contrived, keep in mind that some
AbstractDict
containers are explicitly designed to reference literally all kinds of objects, IIUC especially within the compiler. It would make sense to me if thefind*
interface worked without limitations for these important containers).Until now I have been more familiar with the
findall
API which gives distinctive answers (that I would expect) in all 3 cases:I'm not sure if other people knew about this previously, or view this as a problem, and if so, how we might go about addressing this?
The text was updated successfully, but these errors were encountered: