Skip to content

Commit af25366

Browse files
author
Pietro Vertechi
committed
Rename createtype to add_params and cleanup
1 parent 1f661e2 commit af25366

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

src/collect.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function grow_to_structarray!(dest::AbstractArray, itr, elem = iterate(itr))
110110
end
111111

112112
function to_structarray(::Type{T}, nt::C) where {T, C<:Tup}
113-
S = createtype(T, eltypes(C))
113+
S = add_params(T, eltypes(astuple(C)))
114114
return StructArray{S}(nt)
115115
end
116116

@@ -122,7 +122,7 @@ function widenstructarray(dest::StructArray{T}, i, ::Type{S}) where {T, S}
122122
types = ntuple(i -> fieldtype(sch, i), fieldcount(sch))
123123
cols = fieldarrays(dest)
124124
if names == propertynames(cols)
125-
nt = map((a, b) -> widenstructarray(a, i, b), cols, strip_types(sch)(types))
125+
nt = map((a, b) -> widenstructarray(a, i, b), cols, strip_params(sch)(types))
126126
return to_structarray(T, nt)
127127
else
128128
return widenarray(dest, i, S)

src/interface.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ end
99

1010
staticschema(::Type{T}) where {T<:Tup} = T
1111

12-
tuple_type(::Type{NamedTuple{names, types}}) where {names, types} = types
13-
tuple_type(::Type{T}) where {T<:Tuple} = T
12+
astuple(::Type{NamedTuple{names, types}}) where {names, types} = types
13+
astuple(::Type{T}) where {T<:Tuple} = T
1414

1515
function fields(::Type{T}) where {T}
1616
fieldnames(staticschema(T))
1717
end
1818

19-
strip_types(::Type{<:Tuple}) = Tuple
20-
strip_types(::Type{<:NamedTuple{names}}) where {names} = NamedTuple{names}
19+
strip_params(::Type{<:Tuple}) = Tuple
20+
strip_params(::Type{<:NamedTuple{names}}) where {names} = NamedTuple{names}

src/structarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ _dims(c::Tup) = length(axes(c[1]))
2222
_dims(c::EmptyTup) = 1
2323

2424
function StructArray{T}(c::C) where {T, C<:Tup}
25-
cols = strip_types(staticschema(T))(c)
25+
cols = strip_params(staticschema(T))(c)
2626
StructArray{T, _dims(cols), typeof(cols)}(cols)
2727
end
2828

src/utils.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,18 @@ createinstance(::Type{T}, args...) where {T<:Union{Tuple, NamedTuple}} = T(args)
6161
Expr(:block, new_tup, construct)
6262
end
6363

64-
createtype(::Type{T}, ::Type{C}) where {T<:Tup, C<:Tup} = C
65-
function createtype(::Type{<:Pair}, ::Type{C}) where {C<:Tup}
66-
tp = tuple_type(C).parameters
67-
Pair{tp[1], tp[2]}
68-
end
69-
createtype(::Type{T}, ::Type{C}) where {T, C<:Tup} = T
64+
add_params(::Type{T}, ::Type{C}) where {T, C<:Tuple} = T
65+
add_params(::Type{T}, ::Type{C}) where {T<:Tuple, C<:Tuple} = C
66+
add_params(::Type{<:NamedTuple{names}}, ::Type{C}) where {names, C<:Tuple} = NamedTuple{names, C}
67+
add_params(::Type{<:Pair}, ::Type{Tuple{S, T}}) where {S, T} = Pair{S, T}
7068

7169
"""
7270
`iscompatible(::Type{S}, ::Type{V}) where {S, V<:AbstractArray}`
7371
7472
Check whether element type `S` can be pushed to a container of type `V`.
7573
"""
7674
iscompatible(::Type{S}, ::Type{<:AbstractArray{T}}) where {S, T} = S<:T
77-
iscompatible(::Type{S}, ::Type{StructArray{T, N, C}}) where {S, T, N, C} = iscompatible(tuple_type(staticschema(S)), tuple_type(C))
75+
iscompatible(::Type{S}, ::Type{StructArray{T, N, C}}) where {S, T, N, C} = iscompatible(astuple(staticschema(S)), astuple(C))
7876

7977
iscompatible(::Type{Tuple{}}, ::Type{T}) where {T<:Tuple} = false
8078
iscompatible(::Type{T}, ::Type{Tuple{}}) where {T<:Tuple} = false

0 commit comments

Comments
 (0)