Skip to content

should deleteat! be implemented for OrderedDict ? #146

Open
@filchristou

Description

@filchristou

Currently deleteat! doesn't seem to work although i would personally expect it to.

julia> od = OrderedDict(UUID(1) => "ena", UUID(2) => "dio", UUID(3) => "tria", UUID(4) => "tessera")
OrderedDict{UUID, String} with 4 entries:
  UUID("00000000-0000-0000-0000-000000000001") => "ena"
  UUID("00000000-0000-0000-0000-000000000002") => "dio"
  UUID("00000000-0000-0000-0000-000000000003") => "tria"
  UUID("00000000-0000-0000-0000-000000000004") => "tessera"

julia> deleteat!(od, 3)
ERROR: MethodError: no method matching deleteat!(::OrderedDict{UUID, String}, ::Int64)
The function `deleteat!` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  deleteat!(::BitVector, ::Integer)
   @ Base bitarray.jl:953
  deleteat!(::BitVector, ::Any)
   @ Base bitarray.jl:986
  deleteat!(::Vector, ::Integer)
   @ Base array.jl:1770
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[33]:1

The implementation could be as easy as:

julia> mydeleteat!(od::OrderedDict, i::Int) = delete!(od, IterTools.nth(od, i)[1])
mydeleteat! (generic function with 1 method)

julia> mydeleteat!(od , 3)
OrderedDict{UUID, String} with 3 entries:
  UUID("00000000-0000-0000-0000-000000000001") => "ena"
  UUID("00000000-0000-0000-0000-000000000002") => "dio"
  UUID("00000000-0000-0000-0000-000000000004") => "tessera"

If you agree with adding this functionality let me know and I could do a PR.
In this case, if you find something wrong with mydeleteat implementation let me know.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions