IsIndexed trait

I’m trying to understand is something like a IsIndexed trait exists already, or not.

This trait would be true for all things which:

  • are collections
  • and for each element there is[1] one key which has O(1) access.

The following (and possibly more) stdlib collection interfaces would evaluate to true: Collections and Data Structures · The Julia Language, although my definition doesn’t require firstindex or lastindex.

I think where such a trait would become interesting would be that iterators could use it to decide whether the underlying datastructure supports views: if IsIndexed(T) then the element of the iterator should be a view of T.

It’s possible that the problem of deciding on whether something should be a view or a copy is already solved generally in a different way and I’m not aware.

[1] exactly one key? possible more? I don’t know.