Skip to content

Commit a51015c

Browse files
authored
Allow non-Function callables to be used in count(f, itr) (#36187)
1 parent e6eafce commit a51015c

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

base/reduce.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ end
840840

841841
## count
842842

843-
_bool(f::Function) = x->f(x)::Bool
843+
_bool(f) = x->f(x)::Bool
844844

845845
"""
846846
count(p, itr) -> Integer

test/reduce.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,11 @@ end
480480
@test count(!iszero, Int[1]) == 1
481481
@test count(!iszero, [1, 0, 2, 0, 3, 0, 4]) == 4
482482

483+
struct NonFunctionIsZero end
484+
(::NonFunctionIsZero)(x) = iszero(x)
485+
@test count(NonFunctionIsZero(), []) == 0
486+
@test count(NonFunctionIsZero(), [0]) == 1
487+
@test count(NonFunctionIsZero(), [1]) == 0
483488

484489
## cumsum, cummin, cummax
485490

0 commit comments

Comments
 (0)