This commit is contained in:
2026-07-13 10:24:29 +07:00
parent c4eeb99aba
commit c56fc7366c
+9 -9
View File
@@ -235,7 +235,7 @@ Does **not** mutate the input; it always allocates new containers.
# Examples # Examples
```jldoctest ```jldoctest
julia> using JSON julia> using JSON, DataStructures
julia> d = Dict( julia> d = Dict(
"a" => 4, "a" => 4,
"b" => 6, "b" => 6,
@@ -278,9 +278,9 @@ OrderedDict{String,Int} with 3 entries:
"b" => 2 "b" => 2
``` ```
""" """
function dictify(x; keytype::Type=Any, sort_order::Union{Nothing, Vector}=nothing) function dictify(x::T; keytype::Type=Any, sort_order::Union{Nothing, Vector}=nothing
)::OrderedDict where {T<:AbstractDict}
# Dict-like objects # Dict-like objects
if x isa AbstractDict
out = OrderedDict{keytype, Any}() out = OrderedDict{keytype, Any}()
# 1. Process and normalize all keys from the input dictionary # 1. Process and normalize all keys from the input dictionary
@@ -328,17 +328,17 @@ function dictify(x; keytype::Type=Any, sort_order::Union{Nothing, Vector}=nothin
end end
return out return out
end
# Arrays / vectors: map elements recursively function dictify(x::T; keytype::Type=Any, sort_order::Union{Nothing, Vector}=nothing
elseif x isa AbstractArray ) where {T<:AbstractArray}
return [dictify(element; keytype=keytype, sort_order=sort_order) for element in x] return [dictify(element; keytype=keytype, sort_order=sort_order) for element in x]
end
# Everything else: return as-is function dictify(x; keytype::Type=Any, sort_order::Union{Nothing, Vector}=nothing
else )
return x return x
end end
end
# ---------------------------------------------- 100 --------------------------------------------- # # ---------------------------------------------- 100 --------------------------------------------- #