Skip to content

Commit cc9f984

Browse files
authored
Merge pull request #182 from aplavin/structarrays
simplify StructArrays handling
2 parents 3424708 + d8d9d03 commit cc9f984

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

ext/AccessorsStructArraysExt.jl

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@ Accessors.delete(x::StructArray{<:Union{Tuple, NamedTuple}}, o::PropertyLens) =
1111

1212
Accessors.set(x::StructArray{<:Union{Tuple, NamedTuple}}, ::typeof(propertynames), names) = set(x, propertynames StructArrays.components, names)
1313

14-
# (named)tuple eltypes: only component arrays themselves are needed in the constructor
15-
# can change component number/names
16-
Accessors.set(x::StructArray{<:Union{Tuple, NamedTuple}}, ::typeof(StructArrays.components), v) = StructArray(v)
14+
Accessors.set(x::StructArray, ::typeof(StructArrays.components), v) = constructorof(typeof(x))(v)
1715

18-
# other eltypes: need to pass eltype to the constructor in addition to component arrays
19-
# component number/names stay the same
20-
function Accessors.set(x::StructArray{T}, ::typeof(StructArrays.components), v::VT) where {T, VT}
21-
# resulting eltype is basically T, but potentially with different type parameters
22-
# probe its constructorof to get the right concrete type
23-
ET = Base.promote_op(constructorof(T), map(eltype, _eltypes(VT))...)
24-
StructArray{ET}(v)
25-
end
26-
27-
_eltypes(::Type{T}) where {T <: Tuple} = Tuple(T.parameters)
28-
_eltypes(::Type{NamedTuple{K, T}}) where {K, T <: Tuple} = Tuple(T.parameters)
2916
end

0 commit comments

Comments
 (0)