Skip to content

Commit

Permalink
Update error message and tests for more permissive any/all with non-b…
Browse files Browse the repository at this point in the history
…oolean collections
  • Loading branch information
fcard committed Oct 16, 2016
1 parent 6c9f5af commit b055a1a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 2 additions & 4 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,8 @@ false
all(itr) = all(identity, itr)

nonboolean_error(f, op) = throw(ArgumentError("""
Using non-boolean collections with $f(itr) is not allowed, use
reduce($op, itr) instead. If you are using $f(map(f, itr)) or
$f([f(x) for x in itr]), use $f(f, itr) instead.
"""))
Using non-boolean collections with $f(itr) is not allowed, use reduce($op, itr) instead.
"""))
or_bool_only(a, b) = nonboolean_error(:any, :|)
or_bool_only(a::Bool, b::Bool) = a|b
and_bool_only(a, b) = nonboolean_error(:all, :&)
Expand Down
17 changes: 17 additions & 0 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,23 @@ let c = [0, 0], A = 1:1000
@test c == [10,10]
end

# any/all with non-boolean collections

let f(x) = x == 1 ? true : x == 2 ? false : 1
@test any(Any[false,true,false])
@test any(map(f, [2,1,2]))
@test any([f(x) for x in [2,1,2]])

@test all(Any[true,true,true])
@test all(map(f, [1,1,1]))
@test all([f(x) for x in [1,1,1]])

@test_throws ArgumentError any([1,true])
@test_throws ArgumentError all([true,1])
@test_throws ArgumentError any(map(f,[1,3]))
@test_throws ArgumentError all(map(f,[1,3]))
end

# any and all with functors

immutable SomeFunctor end
Expand Down

0 comments on commit b055a1a

Please sign in to comment.