Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IsIterable trait #25

Merged
merged 5 commits into from
Feb 22, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/base-traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ using SimpleTraits
using Compat

export IsLeafType, IsBits, IsImmutable, IsContiguous, IsIndexLinear,
IsAnything, IsNothing, IsCallable

@static if VERSION >= v"0.6.0-dev"
export IsIterable
end
IsAnything, IsNothing, IsCallable, IsIterable

"Trait which contains all types"
@traitdef IsAnything{X}
Expand Down Expand Up @@ -61,11 +57,10 @@ end

Base.@deprecate_binding IsFastLinearIndex IsIndexLinear

@static if VERSION >= v"0.6.0-dev"
@traitdef IsIterable{X}
@generated function SimpleTraits.trait{X}(::Type{IsIterable{X}})
method_exists(start, Tuple{X}) ? :(IsIterable{X}) : :(Not{IsIterable{X}})
end
"Trait of all iterable types"
@traitdef IsIterable{X}
@generated function SimpleTraits.trait{X}(::Type{IsIterable{X}})
method_exists(start, Tuple{X}) ? :(IsIterable{X}) : :(Not{IsIterable{X}})
end

end # module
8 changes: 4 additions & 4 deletions test/base-traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if VERSION < v"0.5.0-dev"
@test istrait(IsCallable{Base.AddFun})
end

if VERSION >= v"0.6.0-dev"
@test istrait(IsIterable{Array})
@test !istrait(IsIterable{Cmd})
end
@test istrait(IsIterable{Array})
@test !istrait(IsIterable{Cmd})
@test method_exists(start, Tuple{Base.UnitRange{Int}})
@test method_exists(start, Tuple{Base.UnitRange})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I wasn't clear at all, I meant:

@test istrait(IsIterable{Base.UnitRange{Int}})
@test istrait(IsIterable{Base.LogicalIndex})

and not testing the method_exists directly.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that, LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second one should also test UnitRange, not LogicalIndex, right?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Just trying to confuse you more ;-)