Indexing arrays with symbols

I came over the following thread and was wondering if there is still an intuitive way to index an array with symbols.

Say if

> arr = [1,2,3]

could be still indexed with
> arr[:a], arr[:b], arr[:c]

Background: I want to have a generic function that works both on a function argument that corresponds to an array or a dictionary of symbols.

It depends on what you want to do, but using something like eachindex might work.

Or write a method that takes a Dict and converts it to an Array first and then passes it to your method that takes an Array.

If you really want an array that can be indexed with Symbols, you could make your own type that acts like an Array, and then add a method to Base.getindex for your type that can take Symbols.

1 Like

Use NamedArrays.jl

2 Likes