<!--
{
  "documentType" : "article",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/EnumeratedSequence/BidirectionalCollection-Implementations",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "BidirectionalCollection Implementations"
}
-->

# BidirectionalCollection Implementations

## Topics

### Instance Properties

[`var last: Self.Element?`](/documentation/Swift/EnumeratedSequence/last)

The last element of the collection.

### Instance Methods

[`func difference<C>(from: C, by: (C.Element, Self.Element) -> Bool) -> CollectionDifference<Self.Element>`](/documentation/Swift/EnumeratedSequence/difference(from:by:))

Returns the difference needed to produce this collection’s ordered
elements from the given collection, using the given predicate as an
equivalence test.

[`func distance(from: Self.Index, to: Self.Index) -> Int`](/documentation/Swift/EnumeratedSequence/distance(from:to:)-90p1a)

[`func formIndex(before: inout Self.Index)`](/documentation/Swift/EnumeratedSequence/formIndex(before:))

Replaces the given index with its predecessor.

[`func index(Self.Index, offsetBy: Int) -> Self.Index`](/documentation/Swift/EnumeratedSequence/index(_:offsetBy:)-5oheh)

[`func index(Self.Index, offsetBy: Int, limitedBy: Self.Index) -> Self.Index?`](/documentation/Swift/EnumeratedSequence/index(_:offsetBy:limitedBy:)-3spm1)

[`func index(before: EnumeratedSequence<Base>.Index) -> EnumeratedSequence<Base>.Index`](/documentation/Swift/EnumeratedSequence/index(before:))

Returns the position immediately before the given index.

[`func last(where: (Self.Element) throws -> Bool) rethrows -> Self.Element?`](/documentation/Swift/EnumeratedSequence/last(where:))

Returns the last element of the sequence that satisfies the given
predicate.

[`func lastIndex(where: (Self.Element) throws -> Bool) rethrows -> Self.Index?`](/documentation/Swift/EnumeratedSequence/lastIndex(where:))

Returns the index of the last element in the collection that matches the
given predicate.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)