diff --git a/Project.toml b/Project.toml index c06488f9..be43218c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "StructArrays" uuid = "09ab397b-f2b6-538f-b94a-2f83cf4a842a" -version = "0.6.13" +version = "0.6.14" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/structarray.jl b/src/structarray.jl index 8ec7f04f..843401f7 100644 --- a/src/structarray.jl +++ b/src/structarray.jl @@ -450,12 +450,13 @@ function Base.sizehint!(s::StructArray, i::Integer) end for op in [:cat, :hcat, :vcat] + curried_op = Symbol(:curried, op) @eval begin - function Base.$op(arg1::StructArray, argsrest::StructArray...; kwargs...) - args = (arg1, argsrest...) - f = key -> $op((getproperty(t, key) for t in args)...; kwargs...) + function Base.$op(arg::StructArray, others::StructArray...; kwargs...) + $curried_op(A...) = $op(A...; kwargs...) + args = (arg, others...) T = mapreduce(eltype, promote_type, args) - StructArray{T}(map(f, propertynames(arg1))) + StructArray{T}(map($curried_op, map(components, args)...)) end end end diff --git a/test/runtests.jl b/test/runtests.jl index 9dd3b43b..e74926e0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -636,8 +636,11 @@ end horizontal_concat = StructArray{Pair{Int, String}}(([3 1; 5 6], ["a" "a"; "b" "b"])) @test cat(t, t2; dims=2)::StructArray == horizontal_concat == hcat(t, t2) @test hcat(t, t2) isa StructArray - - # check that cat(dims=1) doesn't commit type piracy (#254) + t3 = StructArray(x=view([1], 1:1:1), y=view([:a], 1:1:1)) + @test @inferred(vcat(t3)) == t3 + @inferred vcat(t3, t3) + @inferred vcat(t3, collect(t3)) + # Check that `cat(dims=1)` doesn't commit type piracy (#254) # We only test that this works, the return value is immaterial @test cat(dims=1) == vcat() end