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

# BidirectionalCollection Implementations

## Topics

### Instance Properties

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

The last element of the collection.

### Instance Methods

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

Returns the difference needed to produce this collection’s ordered
elements from the given collection.

[`func difference<C>(from: C, by: (C.Element, Self.Element) -> Bool) -> CollectionDifference<Self.Element>`](/documentation/Swift/Slice/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 formIndex(before: inout Slice<Base>.Index)`](/documentation/Swift/Slice/formIndex(before:))

Replaces the given index with its predecessor.

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

Replaces the given index with its predecessor.

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

Returns the position immediately before the given index.

[`func joined(separator: String) -> String`](/documentation/Swift/Slice/joined(separator:)-6sxlg)

Returns a new string by concatenating the elements of the sequence,
adding the given separator between each element.

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

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

[`func lastIndex(of: Self.Element) -> Self.Index?`](/documentation/Swift/Slice/lastIndex(of:))

Returns the last index where the specified value appears in the
collection.

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

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

[`func popLast() -> Self.Element?`](/documentation/Swift/Slice/popLast()-7zlp7)

Removes and returns the last element of the collection.

[`func removeLast() -> Self.Element`](/documentation/Swift/Slice/removeLast()-29ty4)

Removes and returns the last element of the collection.

[`func removeLast(Int)`](/documentation/Swift/Slice/removeLast(_:)-4ijd6)

Removes the given number of elements from the end of the collection.

---

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)