update
This commit is contained in:
+12
-12
@@ -235,7 +235,7 @@ Does **not** mutate the input; it always allocates new containers.
|
||||
|
||||
# Examples
|
||||
```jldoctest
|
||||
julia> using JSON
|
||||
julia> using JSON, DataStructures
|
||||
julia> d = Dict(
|
||||
"a" => 4,
|
||||
"b" => 6,
|
||||
@@ -278,9 +278,9 @@ OrderedDict{String,Int} with 3 entries:
|
||||
"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
|
||||
if x isa AbstractDict
|
||||
out = OrderedDict{keytype, Any}()
|
||||
|
||||
# 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
|
||||
|
||||
return out
|
||||
|
||||
# Arrays / vectors: map elements recursively
|
||||
elseif x isa AbstractArray
|
||||
return [dictify(element; keytype=keytype, sort_order=sort_order) for element in x]
|
||||
|
||||
# Everything else: return as-is
|
||||
else
|
||||
return x
|
||||
end
|
||||
end
|
||||
|
||||
function dictify(x::T; keytype::Type=Any, sort_order::Union{Nothing, Vector}=nothing
|
||||
) where {T<:AbstractArray}
|
||||
return [dictify(element; keytype=keytype, sort_order=sort_order) for element in x]
|
||||
end
|
||||
|
||||
function dictify(x; keytype::Type=Any, sort_order::Union{Nothing, Vector}=nothing
|
||||
)
|
||||
return x
|
||||
end
|
||||
|
||||
# ---------------------------------------------- 100 --------------------------------------------- #
|
||||
|
||||
|
||||
Reference in New Issue
Block a user