Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix package when Base.delete is defined #12

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions src/PropertyDicts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,28 @@ end
return dst
end
end
if isdefined(Base, :delete)
import Base: delete
else
delete(collection, k) = delete!(copy(collection), k)
function delete(d::Base.ImmutableDict{K,V}, key) where {K,V}
if isdefined(d, :parent)
if isequal(d.key, key)
d.parent
else
Base.ImmutableDict{K,V}(delete(d.parent, key), d.key, d.value)
end

delete(collection, k) = delete!(copy(collection), k)
function delete(d::Base.ImmutableDict{K,V}, key) where {K,V}
if isdefined(d, :parent)
if isequal(d.key, key)
d.parent
else
d
Base.ImmutableDict{K,V}(delete(d.parent, key), d.key, d.value)
end
else
d
end
function delete(nt::NamedTuple{syms}, key::Symbol) where {syms}
idx = Base.fieldindex(typeof(nt), key, false)
if idx === 0
return nt
else
nv = Val{nfields(syms) - 1}()
NamedTuple{
ntuple(j -> j < idx ? getfield(syms, j) : getfield(syms, j + 1), nv)
}(ntuple(j -> j < idx ? getfield(nt, j) : getfield(nt, j + 1), nv))
end
end
function delete(nt::NamedTuple{syms}, key::Symbol) where {syms}
idx = Base.fieldindex(typeof(nt), key, false)
if idx === 0
return nt
else
nv = Val{nfields(syms) - 1}()
NamedTuple{
ntuple(j -> j < idx ? getfield(syms, j) : getfield(syms, j + 1), nv)
}(ntuple(j -> j < idx ? getfield(nt, j) : getfield(nt, j + 1), nv))
end
end
#endregion
Expand Down
Loading