OrderedSet firstIndex unclear

There is the method on an instance of OrderedSet
func firstIndex(of element: Element) -> Int?
But, OrderedSet is a collection of unique elements, a collection can contain only one unique item. So
it might be worth calling this method ?
func onlyOneIndex(of element: Element) -> Int?

If I'm not mistaken, OrderedSet doesn't even implement this method explicitly. It inherits it from conforming to RandomAccessCollection.

There's plenty of methods that don't quite make sense (e.g. Dictionary has a first and last). It looks like it's really hard to pin down all the possible data structures using so few protocols

It is defined in extension of OrderedSet, but I missed the doc notation above it
OrderedSet members are always unique, so the first index of an element is always the same as its last index. So it was named intend.

Terms of Service

Privacy Policy

Cookie Policy