A collection that supports backward as well as forward traversal.
Bidirectional collections offer traversal backward from any valid index, not including a collection’s
startIndex. Bidirectional collections can therefore offer additional operations, such as a
last property that provides efficient access to the last element and a
reversed() method that presents the elements in reverse order. In addition, bidirectional collections have more efficient implementations of some sequence and collection methods, such as
Conforming to the BidirectionalCollection Protocol
BidirectionalProtocol conformance to your custom types, implement the
index(before:) method in addition to the requirements of the
Indices that are moved forward and backward in a bidirectional collection move by the same amount in each direction. That is, for any index
i into a bidirectional collection
i >= c.startIndex && i < c.endIndex,
c.index(before: c.index(after: i)) == i.
i > c.startIndex && i <= c.endIndex
c.index(after: c.index(before: i)) == i.