From a1a73a4b3fe3bb5504d07debab5ddbedcceecd5e Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Wed, 22 Feb 2017 10:10:17 -0800 Subject: [PATCH 1/5] Add IsIterable trait --- src/base-traits.jl | 11 +++++++++++ test/base-traits.jl | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/base-traits.jl b/src/base-traits.jl index eb1ac3c..fdee5ec 100644 --- a/src/base-traits.jl +++ b/src/base-traits.jl @@ -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} + @generated function SimpleTraits.trait{X}(::Type{IsIterable{X}}) + method_exists(start, Tuple{X}) ? :(IsIterable{X}) : :(Not{IsIterable{X}}) + end +end + end # module diff --git a/test/base-traits.jl b/test/base-traits.jl index 3c66a4a..36a3156 100644 --- a/test/base-traits.jl +++ b/test/base-traits.jl @@ -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}) +end From a2460327af8568faf778cf57c328ad3a7f1f63d2 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Wed, 22 Feb 2017 12:10:07 -0800 Subject: [PATCH 2/5] Enable IsIterable on julia 0.5 --- src/base-traits.jl | 14 ++++---------- test/base-traits.jl | 6 ++---- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/base-traits.jl b/src/base-traits.jl index fdee5ec..4675bce 100644 --- a/src/base-traits.jl +++ b/src/base-traits.jl @@ -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} @@ -61,11 +57,9 @@ 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 +@traitdef IsIterable{X} +@generated function SimpleTraits.trait{X}(::Type{IsIterable{X}}) + method_exists(start, Tuple{X}) ? :(IsIterable{X}) : :(Not{IsIterable{X}}) end end # module diff --git a/test/base-traits.jl b/test/base-traits.jl index 36a3156..4152ced 100644 --- a/test/base-traits.jl +++ b/test/base-traits.jl @@ -31,7 +31,5 @@ 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}) From 5e082f34277309c57899fcc81eea17728e73c610 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Wed, 22 Feb 2017 12:10:35 -0800 Subject: [PATCH 3/5] Add docstring to IsIterable trait --- src/base-traits.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/base-traits.jl b/src/base-traits.jl index 4675bce..28f90ed 100644 --- a/src/base-traits.jl +++ b/src/base-traits.jl @@ -57,6 +57,7 @@ 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}}) From 91d0432d2cc33b30d63ae5111fdfac38baebaf1f Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Wed, 22 Feb 2017 12:10:52 -0800 Subject: [PATCH 4/5] Add test for method_exists --- test/base-traits.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/base-traits.jl b/test/base-traits.jl index 4152ced..26a908a 100644 --- a/test/base-traits.jl +++ b/test/base-traits.jl @@ -33,3 +33,5 @@ end @test istrait(IsIterable{Array}) @test !istrait(IsIterable{Cmd}) +@test method_exists(start, Tuple{Base.UnitRange{Int}}) +@test method_exists(start, Tuple{Base.UnitRange}) From fd6948667c94144fd18e1e15af1a41a73b495040 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Wed, 22 Feb 2017 12:51:37 -0800 Subject: [PATCH 5/5] Fix IsIterable tests --- test/base-traits.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/base-traits.jl b/test/base-traits.jl index 26a908a..1eae587 100644 --- a/test/base-traits.jl +++ b/test/base-traits.jl @@ -33,5 +33,5 @@ end @test istrait(IsIterable{Array}) @test !istrait(IsIterable{Cmd}) -@test method_exists(start, Tuple{Base.UnitRange{Int}}) -@test method_exists(start, Tuple{Base.UnitRange}) +@test istrait(IsIterable{Base.UnitRange{Int}}) +@test istrait(IsIterable{Base.UnitRange})