Skip to content

filter(f, keys(::OrderedDict)) gives an unordered Set #147

@MasonProtter

Description

@MasonProtter

I ran into some surprising bugs recently due to this unexpected behaviour:

julia> d = OrderedDict(1 => :a, 2 => :b, 3 => :c);

julia> filter(iseven, keys(d))
Set{Int64} with 1 element:
  2

julia> filter(isodd, keys(d))
Set{Int64} with 2 elements:
  3
  1

It seems that the problem is that keys(::OrderedDict)::Base.KeySet. KeySet preserves the order, but filter on the KeySet produces a Base.Set.

I think this package should have its own KeySet like type with its own dispatches so it acts correctly in the face of things like filter.

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