You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use this a lot for building generated functions. It turns the type of a named tuple into a named tuple. So you can manipulate it very easily and build static code specialized for a given type.
export schema
""" schema(::Type)`schema` turns a type into a value that's easier to work with.Example: julia> nt = (a=(b=[1,2],c=(d=[3,4],e=[5,6])),f=[7,8]); julia> NT = typeof(nt) NamedTuple{(:a, :f),Tuple{NamedTuple{(:b, :c),Tuple{Array{Int64,1},NamedTuple{(:d, :e),Tuple{Array{Int64,1},Array{Int64,1}}}}},Array{Int64,1}}} julia> schema(NT) (a = (b = Array{Int64,1}, c = (d = Array{Int64,1}, e = Array{Int64,1})), f = Array{Int64,1})"""function schema endfunctionschema(NT::Type{NamedTuple{names, T}}) where {names, T}
returnnamedtuple(fieldnames(NT), schema(valtype(NT)))
endfunctionschema(TT::Type{T}) where {T <:Tuple}
returnschema.(Tuple(TT.types))
endschema(t::T) where {T <:Tuple} =schema(T)
schema(t::T) where {T <:NamedTuple} =schema(T)
schema(T) = T
The text was updated successfully, but these errors were encountered:
I use this a lot for building generated functions. It turns the type of a named tuple into a named tuple. So you can manipulate it very easily and build static code specialized for a given type.
The text was updated successfully, but these errors were encountered: