diff --git a/src/structarray.jl b/src/structarray.jl index 4cfacdcf..d83ccbd3 100644 --- a/src/structarray.jl +++ b/src/structarray.jl @@ -413,6 +413,13 @@ function Base.deleteat!(s::StructVector{T}, idxs) where T return StructVector{T}(t) end +@static if VERSION >= v"1.7.0" + function Base.keepat!(s::StructVector{T}, idxs) where T + t = map(Base.Fix2(keepat!, idxs), components(s)) + return StructVector{T}(t) + end +end + Base.copyto!(I::StructArray, J::StructArray) = (foreachfield(copyto!, I, J); I) function Base.copyto!(I::StructArray, doffs::Integer, J::StructArray, soffs::Integer, n::Integer) diff --git a/test/runtests.jl b/test/runtests.jl index 736d96ff..9f4c95ac 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -259,6 +259,10 @@ end @test d == c == StructArray(a=[1,10,2,3], b=[2,20,3,4], c=["a","A","b","c"]) d = deleteat!(c, 2) @test d == c == StructArray(a=[1,2,3], b=[2,3,4], c=["a","b","c"]) + if Base.VERSION >= v"1.7.0" + d = keepat!(c, 2) + @test d == c == StructArray(a=[2], b=[3], c=["b"]) + end c = StructArray(a=[1], b=[2], c=["a"]) d = [(a=10, b=20, c="A")] @@ -295,6 +299,10 @@ end @test d == c == StructArray{C}(a=[1,10,2,3], b=[2,20,3,4], c=["a","A","b","c"]) d = deleteat!(c, 2) @test d == c == StructArray{C}(a=[1,2,3], b=[2,3,4], c=["a","b","c"]) + if Base.VERSION >= v"1.7.0" + d = keepat!(c, 2) + @test d == c == StructArray{C}(a=[2], b=[3], c=["b"]) + end c = StructArray{C}(a=[1], b=[2], c=["a"]) d = [C(10, 20, "A")]