From 4fdfe36ea03bf87ebac1997df1c3ce89ce2e3715 Mon Sep 17 00:00:00 2001 From: Jonnie Diegelman Date: Fri, 26 Jul 2024 16:33:53 -0400 Subject: [PATCH] Make `haskey` work for `LazyArray` --- Project.toml | 2 +- src/lazyarray.jl | 2 ++ test/runtests.jl | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 47e51390..bfa4222e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ComponentArrays" uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66" authors = ["Jonnie Diegelman <47193959+jonniedie@users.noreply.github.com>"] -version = "0.15.15" +version = "0.15.16" [deps] ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" diff --git a/src/lazyarray.jl b/src/lazyarray.jl index 7262d41d..99b3dff3 100644 --- a/src/lazyarray.jl +++ b/src/lazyarray.jl @@ -30,6 +30,8 @@ Base.propertynames(a::LazyArray) = propertynames(first(a)) Base.keys(a::LazyArray) = Base.OneTo(length(a)) +Base.haskey(a::LazyArray, i::Integer) = i in keys(a) + Base.iterate(a::LazyArray) = iterate(getfield(a, :gen)) Base.iterate(a::LazyArray, state...) = iterate(getfield(a, :gen), state...) diff --git a/test/runtests.jl b/test/runtests.jl index 1b14a266..21018ac9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -345,6 +345,9 @@ end @test propertynames(ca2) == (:a, :b, :c) # ComponentArray @test propertynames(ca2.b) == (:a, :b) # LazyArray + @test haskey(ca2, :a) # ComponentArray + @test haskey(ca2.b, 1) # LazyArray + @test keys(ca2) == (:a, :b, :c) @test keys(ca2.b) == Base.OneTo(2) end