Skip to content

Commit

Permalink
Add IsIterable trait (#25)
Browse files Browse the repository at this point in the history
Add IsIterable trait
  • Loading branch information
davidanthoff authored and mauro3 committed Feb 22, 2017
1 parent 21a075b commit 9393f4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/base-traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using SimpleTraits
using Compat

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

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

Base.@deprecate_binding IsFastLinearIndex IsIndexLinear

"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
5 changes: 5 additions & 0 deletions test/base-traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ if VERSION < v"0.5.0-dev"
# this give deprecation warning in Julia 0.5
@test istrait(IsCallable{Base.AddFun})
end

@test istrait(IsIterable{Array})
@test !istrait(IsIterable{Cmd})
@test istrait(IsIterable{Base.UnitRange{Int}})
@test istrait(IsIterable{Base.UnitRange})

0 comments on commit 9393f4a

Please sign in to comment.