-
Notifications
You must be signed in to change notification settings - Fork 14
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
Changes from 1 commit
a1a73a4
a246032
5e082f3
91d0432
fd69486
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,10 @@ using Compat | |
export IsLeafType, IsBits, IsImmutable, IsContiguous, IsIndexLinear, | ||
IsAnything, IsNothing, IsCallable | ||
|
||
@static if VERSION >= v"0.6.0-dev" | ||
export IsIterable | ||
end | ||
|
||
"Trait which contains all types" | ||
@traitdef IsAnything{X} | ||
@traitimpl IsAnything{X} <- (x->true)(X) | ||
|
@@ -57,4 +61,11 @@ end | |
|
||
Base.@deprecate_binding IsFastLinearIndex IsIndexLinear | ||
|
||
@static if VERSION >= v"0.6.0-dev" | ||
@traitdef IsIterable{X} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a tiny doc string. |
||
@generated function SimpleTraits.trait{X}(::Type{IsIterable{X}}) | ||
method_exists(start, Tuple{X}) ? :(IsIterable{X}) : :(Not{IsIterable{X}}) | ||
end | ||
end | ||
|
||
end # module |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
if VERSION >= v"0.6.0-dev" | ||
@test istrait(IsIterable{Array}) | ||
@test !istrait(IsIterable{Cmd}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add those two tests for good measure:
(I remember that parameterized methods sometimes tripped up |
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked that this does not work in 0.5?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, I didn't, but it seems to work on 0.5 as well!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW: My comment above about the new type system was related to a "complete" solution to this type of interface specification, as it is done in Traits.jl.