Skip to content

Commit 32cefb0

Browse files
committed
Address #22
1 parent 78b1e56 commit 32cefb0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/ArrayInterface.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ parent_type(::Type{Symmetric{T,S}}) where {T,S} = S
2222
parent_type(::Type{<:LinearAlgebra.AbstractTriangular{T,S}}) where {T,S} = S
2323
parent_type(::Type{T}) where {T} = T
2424

25+
"""
26+
is_dynamic(::Type{T}) -> Bool
27+
28+
Returns `true` if the size of `T` is dynamic. If `T` is dynamic then operations
29+
such as `pop!` and `popfirst!` are available for collections of type `T`.
30+
"""
31+
is_dynamic(x) = is_dynamic(typeof(x))
32+
is_dynamic(::Type{T}) where {T} = false
33+
is_dynamic(::Type{<:Vector}) = true
34+
is_dynamic(::Type{<:AbstractDict}) = true
35+
is_dynamic(::Type{<:Base.ImmutableDict}) = false
36+
2537
function ismutable end
2638

2739
"""

test/runtests.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,17 @@ end
182182

183183
@test isnothing(ArrayInterface.known_last(1:4))
184184
@test isnothing(ArrayInterface.known_last(typeof(1:4)))
185-
185+
186186
@test isnothing(ArrayInterface.known_step(typeof(1:0.2:4)))
187187
@test isone(ArrayInterface.known_step(1:4))
188188
@test isone(ArrayInterface.known_step(typeof(1:4)))
189189
end
190190

191+
@testset "is_dynamic" begin
192+
@test ArrayInterface.is_dynamic([1])
193+
@test ArrayInterface.is_dynamic(Vector{Int})
194+
@test ArrayInterface.is_dynamic(Dict{Symbol,Any})
195+
@test !ArrayInterface.is_dynamic(Base.ImmutableDict{Symbol,Int64})
196+
@test !ArrayInterface.is_dynamic(Tuple{})
197+
end
198+

0 commit comments

Comments
 (0)