Skip to content

Commit

Permalink
Allow non-Function callables to be used in count(f, itr) (#36187)
Browse files Browse the repository at this point in the history
(cherry picked from commit a51015c)
  • Loading branch information
tkf authored and KristofferC committed Jun 9, 2020
1 parent 3854131 commit ea15599
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ end

## count

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

"""
count(p, itr) -> Integer
Expand Down
5 changes: 5 additions & 0 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ end
@test count(!iszero, Int[1]) == 1
@test count(!iszero, [1, 0, 2, 0, 3, 0, 4]) == 4

struct NonFunctionIsZero end
(::NonFunctionIsZero)(x) = iszero(x)
@test count(NonFunctionIsZero(), []) == 0
@test count(NonFunctionIsZero(), [0]) == 1
@test count(NonFunctionIsZero(), [1]) == 0

## cumsum, cummin, cummax

Expand Down

0 comments on commit ea15599

Please sign in to comment.