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

Add IsIterable trait #25

merged 5 commits into from
Feb 22, 2017

Conversation

davidanthoff
Copy link
Contributor

Right now I'm only checking whether a start method is defined. I guess I could also check for next and done, but in some way I feel this should be enough.

@@ -57,4 +61,11 @@ end

Base.@deprecate_binding IsFastLinearIndex IsIndexLinear

@static if VERSION >= v"0.6.0-dev"
@traitdef IsIterable{X}
Copy link
Owner

Choose a reason for hiding this comment

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

Add a tiny doc string.

@@ -6,6 +6,10 @@ using Compat
export IsLeafType, IsBits, IsImmutable, IsContiguous, IsIndexLinear,
IsAnything, IsNothing, IsCallable

@static if VERSION >= v"0.6.0-dev"
Copy link
Owner

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?

Copy link
Contributor Author

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!

Copy link
Owner

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.


if VERSION >= v"0.6.0-dev"
@test istrait(IsIterable{Array})
@test !istrait(IsIterable{Cmd})
Copy link
Owner

Choose a reason for hiding this comment

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

Let's add those two tests for good measure:

julia> method_exists(start, Tuple{Base.UnitRange{Int}})
true

julia> method_exists(start, Tuple{Base.UnitRange})
true

(I remember that parameterized methods sometimes tripped up method_exists. So in case there is a regression.)

@mauro3
Copy link
Owner

mauro3 commented Feb 22, 2017

Thanks for your PR!

@davidanthoff
Copy link
Contributor Author

Alright, I think I addressed all your requests.

@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 ;-)

@mauro3 mauro3 merged commit 9393f4a into mauro3:master Feb 22, 2017
@mauro3
Copy link
Owner

mauro3 commented Feb 22, 2017

Thanks for the contribution!

@davidanthoff davidanthoff deleted the isiterable-trait branch February 22, 2017 21:37
mauro3 added a commit that referenced this pull request Aug 10, 2017
I'm a bit stomped by this test failure as it didn't show up in the CI of PR:
#34

Furthermore, the same issue existed as far back as
#25

I tried to see whether this was introduced in one of the minor
versions of Julia 0.5.  But running the test now locally fails for all
0.5.0, 0.5.1 and 0.5.2.

So, not sure what changed.
mauro3 added a commit that referenced this pull request Aug 10, 2017
I'm a bit stomped by this test failure as it didn't show up in the CI of PR:
#34

Furthermore, the same issue existed as far back as
#25

I tried to see whether this was introduced in one of the minor
versions of Julia 0.5.  But running the test now locally fails for all
0.5.0, 0.5.1 and 0.5.2.

So, not sure what changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants