diff --git a/src/liblazy.jl b/src/liblazy.jl index 947a652..be5f646 100644 --- a/src/liblazy.jl +++ b/src/liblazy.jl @@ -181,8 +181,16 @@ import Base: any, all isempty(xs) == isempty(ys) && (isempty(xs) || first(xs) == first(ys) && tail(xs) == tail(ys)) -any(f, xs::List) = @>> xs map(f) any +if isdefined(Base, :Predicate) + any(f::Base.Predicate, xs::List) = @>> xs map(f) any + all(f::Base.Predicate, xs::List) = @>> xs map(f) all +else + any(f, xs::List) = @>> xs map(f) any + all(f, xs::List) = @>> xs map(f) all +end + @rec any(xs::List) = isempty(xs) ? false : first(xs) || any(tail(xs)) +any(::typeof(@functorize(identity)), xs::List) = any(xs) -all(f, xs::List) = @>> xs map(f) all @rec all(xs::List) = isempty(xs) ? true : first(xs) && all(tail(xs)) +all(::typeof(@functorize(identity)), xs::List) = all(xs) diff --git a/test/runtests.jl b/test/runtests.jl index a21c51f..4b88648 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -60,4 +60,19 @@ facts("Listables") do @fact_throws MethodError sin() end +facts("any/all") do + let xs = list(true, false, false) + @pending any(identity, xs) --> true + @pending any(xs) --> true + @pending all(identity, xs) --> false + @pending all(xs) --> false + end + let yy = list(1, 0, 1) + @pending any(Bool, yy) --> true + @pending all(Bool, yy) --> false + end + # Base method--ensures no ambiguity with methods here + @fact all([true true; true true], 1) --> [true true] +end + FactCheck.exitstatus()