Skip to content
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

Allow non-Function callables to be used in count(f, itr) #36187

Merged
merged 1 commit into from
Jun 8, 2020

Conversation

tkf
Copy link
Member

@tkf tkf commented Jun 8, 2020

Currently, all predicate functions are wrapped with

_bool(f::Function) = x->f(x)::Bool

The signature ::Function is overly restrictive because everything is (potentially) callable.

With this patch, following works

julia> struct NonFunctionIsZero end

julia> (::NonFunctionIsZero)(x) = iszero(x)

julia> count(NonFunctionIsZero(), [])
0

Since this worked in Julia 1.0 and 1.4, I'm marking this as a bugfix.

@tkf tkf added the bugfix This change fixes an existing bug label Jun 8, 2020
@tkf tkf merged commit a51015c into JuliaLang:master Jun 8, 2020
@tkf tkf deleted the count-with-nonfunction branch June 8, 2020 23:27
@tkf
Copy link
Member Author

tkf commented Jun 8, 2020

@KristofferC or someone else: I added the backport label since it's a bugfix. Please feel free to remove it if it's inappropriate.

KristofferC pushed a commit that referenced this pull request Jun 9, 2020
simeonschaub pushed a commit to simeonschaub/julia that referenced this pull request Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants