@@ -314,7 +314,7 @@ directly on an `AbstractAxis`.
314
314
315
315
# Examples
316
316
317
- ```julia-repl
317
+ ```jldoctest
318
318
julia> using ComponentArrays
319
319
320
320
julia> ca = ComponentArray(a=1, b=[1,2,3], c=(a=4,))
@@ -337,6 +337,29 @@ julia> sum(prod(ca[k]) for k in valkeys(ca))
337
337
end
338
338
valkeys (ca:: ComponentVector ) = valkeys (getaxes (ca)[1 ])
339
339
340
+ """
341
+ merge(cvec1::ComponentVector, cvecs::ComponentVector...)
342
+
343
+ Construct a new ComponentVector by merging two or more existing ones, in a left-associative
344
+ manner. If a key is present in two or more CVectors, the right-most CVector takes priority.
345
+ The type of the resulting CVector will be promoted to accomodate all the types of the merged
346
+ CVectors
347
+
348
+ # Examples
349
+ ```jldoctest
350
+ julia> c1 = ComponentArray(a=1.2, b=2.3)
351
+ ComponentVector{Float64}(a = 1.2, b = 2.3)
352
+
353
+ julia> c2 = ComponentArray(a=1,h=4)
354
+ ComponentVector{Int64}(a = 1, h = 4)
355
+
356
+ julia> merge(c1,c2)
357
+ ComponentVector{Float64}(a = 1.0, b = 2.3, h = 4.0)
358
+
359
+ julia> merge(c2,c1)
360
+ ComponentVector{Float64}(a = 1.2, h = 4.0, b = 2.3)
361
+ ```
362
+ """
340
363
function merge (cvec1:: ComponentVector{T1} , cvec2:: ComponentVector{T2} ) where {T1, T2}
341
364
typed_dict = ComponentVector {promote_type(T1, T2)} (cvec1)
342
365
for key in valkeys (cvec2)
0 commit comments