-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 dispatches on ::Function #49085
Comments
You can just pass |
It's not even possible to implement the pattern method in terms of the predicate method, since the pattern matches against slices of the string, not elements. They have quite different contracts. I propose deprecating the pattern method and introducing another function if desired.
|
Looks consistent if its considered in the general sense:
|
This is true in most cases, but there is another do statement for function types:
julia> findfirst(1:10) do x
x > 5
end
6 |
See #10593 for the discussions that have led to the current design. Do we have any actual examples where one would like to pass a callable that isn't a function? |
As always in these cases, we need to worry about the situation where a generic package function That's awkward enough to warrant avoiding this behavior, but it's worse than that: often However the motivation for a new function isn't only generic programming, but also human understanding. As mentioned, the two methods have totally different meanings: one matches a substring while the other takes a single element. It's easier to make sense of a system where each name refers to a single concept rather than multiple vaguely related ones. The pattern method has more in common with |
This doesn't seem correct: I just tried relaxing julia> detect_ambiguities(Base, recursive=true)
1-element Vector{Tuple{Method, Method}}:
(findnext(testf, B::BitArray, start::Integer) @ Base bitarray.jl:1528, findnext(pat::Base.RegexAndMatchData, str, i) @ Base regex.jl:617) So I guess the type restrictions should just be relaxed from |
Technically there may be only one ambiguity, but given that there are methods taking |
This function dispatches on
Function
to avoid ambiguity with thepattern
method, so it is not generic to callable types. This seems like it should be two functions: one that takes a predicate and one that takes a pattern.The text was updated successfully, but these errors were encountered: