WIP/RFC: make find, filter, count more consistent #9340
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is about adding the method
count(A, value)
, ascount(x -> x==value, A)
is frustratingly verbose and slow. Then it is tempting to homogeneize a group of functions which can have those three methods:findnext
andfindfirst
already have them,count
had only 1. (and 3. viacountnz
),find
had 1. and 3.any
andall
, but then it is conflicting withany(A, dims)
taking dimensions. This seems OK to leave it as it is (at least forany(A, value)
<==>value in A
).A
is aDict
, I chose to interpretfilter(A, value)
as comparingvalue
to the values ofA
, not its keys. But thenRegex
makes the opposite choice, which I find surprising:filter!(r::Regex, d::Dict) = filter!((k,v)->ismatch(r,k),d)
. WDYT?findn
andfindnz
would be happy to have those methods added too, butfindnz
looks like it finds non-zeros, so it should be renamed in this case. What does then
infindn
stand for?If this makes sense, I will add some tests before removing WIP.