diff --git a/base/functors.jl b/base/functors.jl index fc2baa880dc40..69bc52d0eac7a 100644 --- a/base/functors.jl +++ b/base/functors.jl @@ -78,8 +78,8 @@ call(f::UnspecializedFun{2}, x, y) = f.f(x,y) # Special purpose functors -type Predicate <: Func{1} - f::Function +type Predicate{F} <: Func{1} + f::F end call(pred::Predicate, x) = pred.f(x)::Bool diff --git a/base/reduce.jl b/base/reduce.jl index 3a1881c409480..7ba0955c325d6 100644 --- a/base/reduce.jl +++ b/base/reduce.jl @@ -357,16 +357,16 @@ function identity end any(itr) = any(IdFun(), itr) all(itr) = all(IdFun(), itr) -any(f::Function, itr) = any(f === identity? IdFun() : Predicate(f), itr) -any(f::Func{1}, itr) = mapreduce_sc_impl(f, OrFun(), itr) -any(f::IdFun, itr) = +any(f::Any, itr) = any(f === identity? IdFun() : Predicate(f), itr) +any(f::Predicate, itr) = mapreduce_sc_impl(f, OrFun(), itr) +any(f::IdFun, itr) = eltype(itr) <: Bool? mapreduce_sc_impl(f, OrFun(), itr) : nonboolean_any(itr) -all(f::Function, itr) = all(f === identity? IdFun() : Predicate(f), itr) -all(f::Func{1}, itr) = mapreduce_sc_impl(f, AndFun(), itr) -all(f::IdFun, itr) = +all(f::Any, itr) = all(f === identity? IdFun() : Predicate(f), itr) +all(f::Predicate, itr) = mapreduce_sc_impl(f, AndFun(), itr) +all(f::IdFun, itr) = eltype(itr) <: Bool? mapreduce_sc_impl(f, AndFun(), itr) : nonboolean_all(itr) diff --git a/test/reduce.jl b/test/reduce.jl index f123f9232df86..4426525086b16 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -216,6 +216,15 @@ let c = [0, 0], A = 1:1000 @test c == [10,10] end +# any and all with functors + +immutable SomeFunctor end +Base.call(::SomeFunctor, x) = true + +@test any(SomeFunctor(), 1:10) +@test all(SomeFunctor(), 1:10) + + # in @test in(1, Int[]) == false