Skip to content

Add array interface to ordered dicts ? #158

@aobliger

Description

@aobliger

Hello,

This is a very nice package.

What would prevent us to add an array interface to redered dicts by doing this

Base.getindex(OD::OrderedDict{K,V}, i::Int) where {K,V} = Base.getindex(OD.vals, i)
Base.getindex(OD::OrderedDict{K,V}, I::UnitRange{T}) where {K,V,T<:Real} = Base.getindex(OD.vals, I)
Base.getindex(OD::OrderedDict{K,V}, I::AbstractRange{T}) where {K,V,T} = Base.getindex(OD.vals, I)
Base.getindex(OD::OrderedDict{K,V}, c::Colon) where {K,V} = Base.getindex(OD.vals, c)
Base.firstindex(OD::OrderedDict{K,V}) where {K,V} = Base.firstindex(OD.vals)
Base.lastindex(OD::OrderedDict{K,V}) where {K,V} = Base.lastindex(OD.vals)

so that OD[1], OD[begin:end], and OD[1:2:end] would work ?

Best,
Amaël

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