Skip to content

Commit

Permalink
Merge pull request #60 from ararslan/aa/ambiguous
Browse files Browse the repository at this point in the history
Fix ambiguities in any/all
  • Loading branch information
MikeInnes authored Mar 27, 2017
2 parents 3d60067 + 6d8309f commit 8ac8678
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/liblazy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 8ac8678

Please sign in to comment.