Skip to content

Commit

Permalink
Adjust non-boolean any/all error again
Browse files Browse the repository at this point in the history
  • Loading branch information
tkelman committed May 27, 2016
1 parent b384f8a commit 1d023e6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -387,21 +387,29 @@ end
any(itr) = any(identity, itr)
all(itr) = all(identity, itr)

nonboolean_error(f, op) = error("""
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.
""")
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, :&)
and_bool_only(a::Bool, b::Bool) = a&b

any(f::Any, itr) = any(Predicate(f), itr)
any(f::Predicate, itr) = mapreduce_sc_impl(f, |, itr)
any(f::typeof(identity), itr) =
eltype(itr) <: Bool ?
mapreduce_sc_impl(f, |, itr) :
reduce(or_bool_only, itr)
or_bool_only(a::Bool, b::Bool) = a | b

all(f::Any, itr) = all(Predicate(f), itr)
all(f::Predicate, itr) = mapreduce_sc_impl(f, &, itr)
all(f::typeof(identity), itr) =
eltype(itr) <: Bool ?
mapreduce_sc_impl(f, &, itr) :
reduce(and_bool_only, itr)
and_bool_only(a::Bool, b::Bool) = a & b

## in & contains

Expand Down

0 comments on commit 1d023e6

Please sign in to comment.