From d8d9d0357897fdba640e987b57b72f976d825554 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Thu, 21 Nov 2024 21:22:26 -0500 Subject: [PATCH] simplify StructArrays handling can just rely on the ConstructionBase support there --- ext/AccessorsStructArraysExt.jl | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/ext/AccessorsStructArraysExt.jl b/ext/AccessorsStructArraysExt.jl index 64742117..13da5633 100644 --- a/ext/AccessorsStructArraysExt.jl +++ b/ext/AccessorsStructArraysExt.jl @@ -11,19 +11,6 @@ Accessors.delete(x::StructArray{<:Union{Tuple, NamedTuple}}, o::PropertyLens) = Accessors.set(x::StructArray{<:Union{Tuple, NamedTuple}}, ::typeof(propertynames), names) = set(x, propertynames ∘ StructArrays.components, names) -# (named)tuple eltypes: only component arrays themselves are needed in the constructor -# can change component number/names -Accessors.set(x::StructArray{<:Union{Tuple, NamedTuple}}, ::typeof(StructArrays.components), v) = StructArray(v) +Accessors.set(x::StructArray, ::typeof(StructArrays.components), v) = constructorof(typeof(x))(v) -# other eltypes: need to pass eltype to the constructor in addition to component arrays -# component number/names stay the same -function Accessors.set(x::StructArray{T}, ::typeof(StructArrays.components), v::VT) where {T, VT} - # resulting eltype is basically T, but potentially with different type parameters - # probe its constructorof to get the right concrete type - ET = Base.promote_op(constructorof(T), map(eltype, _eltypes(VT))...) - StructArray{ET}(v) -end - -_eltypes(::Type{T}) where {T <: Tuple} = Tuple(T.parameters) -_eltypes(::Type{NamedTuple{K, T}}) where {K, T <: Tuple} = Tuple(T.parameters) end