Skip to content

Commit 015d8d2

Browse files
committed
docs
1 parent b5246cd commit 015d8d2

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/componentarray.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ directly on an `AbstractAxis`.
314314
315315
# Examples
316316
317-
```julia-repl
317+
```jldoctest
318318
julia> using ComponentArrays
319319
320320
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))
337337
end
338338
valkeys(ca::ComponentVector) = valkeys(getaxes(ca)[1])
339339

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+
"""
340363
function merge(cvec1::ComponentVector{T1}, cvec2::ComponentVector{T2}) where {T1, T2}
341364
typed_dict = ComponentVector{promote_type(T1, T2)}(cvec1)
342365
for key in valkeys(cvec2)

0 commit comments

Comments
 (0)