Skip to content

Commit a88c0d0

Browse files
Add keys and propertynames to LazyArray
1 parent 6c4bb34 commit a88c0d0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/lazyarray.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ _un_iter(f, iter, idxs) = f(iter[idxs...])
2626

2727
Base.getproperty(a::LazyArray, s::Symbol) = LazyArray(getproperty(item, s) for item in a)
2828

29+
Base.propertynames(a::LazyArray) = propertynames(first(a))
30+
31+
Base.keys(a::LazyArray) = Base.OneTo(length(a))
32+
2933
Base.iterate(a::LazyArray) = iterate(getfield(a, :gen))
3034
Base.iterate(a::LazyArray, state...) = iterate(getfield(a, :gen), state...)
3135

test/runtests.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,17 @@ end
338338
@test A[1, :] == ComponentVector(x = ones(Int, 4))
339339
end
340340

341+
@testset "Properties" begin
342+
@test hasproperty(ca2, :a) # ComponentArray
343+
@test hasproperty(ca2.b, :a) # LazyArray
344+
345+
@test propertynames(ca2) == (:a, :b, :c) # ComponentArray
346+
@test propertynames(ca2.b) == (:a, :b) # LazyArray
347+
348+
@test keys(ca2) == (:a, :b, :c)
349+
@test keys(ca2.b) == Base.OneTo(2)
350+
end
351+
341352
@testset "Component Index" begin
342353
let
343354
ca = ComponentArray(a = 1, b = 2, c = [3, 4], d = (a = [5, 6, 7], b = 8))

0 commit comments

Comments
 (0)