Order Dependent Operations on Set

Perform order-dependent operations common to all collections, as implemented for Set.

Topics

Manipulating Indices

var startIndex: Set<Element>.Index

The starting position for iterating members of the set.

var endIndex: Set<Element>.Index

The “past the end” position for the set—that is, the position one greater than the last valid subscript argument.

func index(after: Set<Element>.Index) -> Set<Element>.Index

Returns the position immediately after the given index.

func formIndex(after: inout Set<Element>.Index)

Replaces the given index with its successor.

func index(Set<Element>.Index, offsetBy: Int) -> Set<Element>.Index

Returns an index that is the specified distance from the given index.

func formIndex(inout Set<Element>.Index, offsetBy: Int)

Offsets the given index by the specified distance.

func index(Set<Element>.Index, offsetBy: Int, limitedBy: Set<Element>.Index) -> Set<Element>.Index?

Returns an index that is the specified distance from the given index, unless that distance is beyond a given limiting index.

func formIndex(inout Set<Element>.Index, offsetBy: Int, limitedBy: Set<Element>.Index) -> Bool

Offsets the given index by the specified distance, or so that it equals the given limiting index.

var indices: DefaultIndices<Set<Element>>

The indices that are valid for subscripting the collection, in ascending order.

Comparing Sets

func elementsEqual<OtherSequence>(OtherSequence) -> Bool

Returns a Boolean value indicating whether this sequence and another sequence contain the same elements in the same order.

func elementsEqual<OtherSequence>(OtherSequence, by: (Element, OtherSequence.Element) -> Bool) -> Bool

Returns a Boolean value indicating whether this sequence and another sequence contain equivalent elements in the same order, using the given predicate as the equivalence test.

func lexicographicallyPrecedes<OtherSequence>(OtherSequence) -> Bool

Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the less-than operator (<) to compare elements.

func lexicographicallyPrecedes<OtherSequence>(OtherSequence, by: (Element, Element) -> Bool) -> Bool

Returns a Boolean value indicating whether the sequence precedes another sequence in a lexicographical (dictionary) ordering, using the given predicate to compare elements.

func starts<PossiblePrefix>(with: PossiblePrefix) -> Bool

Returns a Boolean value indicating whether the initial elements of the sequence are the same as the elements in another sequence.

func starts<PossiblePrefix>(with: PossiblePrefix, by: (Element, PossiblePrefix.Element) -> Bool) -> Bool

Returns a Boolean value indicating whether the initial elements of the sequence are equivalent to the elements in another sequence, using the given predicate as the equivalence test.

Selecting Elements

subscript(Range<Set<Element>.Index>) -> Slice<Set<Element>>

Accesses a contiguous subrange of the collection’s elements.

subscript<R>(R) -> Slice<Set<Element>>

Accesses the contiguous subrange of the collection’s elements specified by a range expression.

func prefix(Int) -> Slice<Set<Element>>

Returns a subsequence, up to the specified maximum length, containing the initial elements of the collection.

func prefix(upTo: Set<Element>.Index) -> Slice<Set<Element>>

Returns a subsequence from the start of the collection up to, but not including, the specified position.

func prefix(through: Set<Element>.Index) -> Slice<Set<Element>>

Returns a subsequence from the start of the collection through the specified position.

func prefix(while: (Element) -> Bool) -> Slice<Set<Element>>

Returns a subsequence containing the initial elements until predicate returns false and skipping the remaining elements.

func suffix(Int) -> Slice<Set<Element>>

Returns a subsequence, up to the given maximum length, containing the final elements of the collection.

func suffix(from: Set<Element>.Index) -> Slice<Set<Element>>

Returns a subsequence from the specified position to the end of the collection.

Excluding Elements

func drop(while: (Element) -> Bool) -> Slice<Set<Element>>

Returns a subsequence by skipping elements while predicate returns true and returning the remaining elements.

func dropFirst(Int) -> Slice<Set<Element>>

Returns a subsequence containing all but the given number of initial elements.

func dropLast(Int) -> Slice<Set<Element>>

Returns a subsequence containing all but the specified number of final elements.

func popFirst() -> Element?

Removes and returns the first element of the set.

Reversing a Set's Elements

func reversed() -> [Element]

Returns an array containing the elements of this sequence in reverse order.

Splitting and Joining Elements

func joined() -> FlattenSequence<Set<Element>>

Returns the elements of this sequence of sequences, concatenated.

func joined<Separator>(separator: Separator) -> JoinedSequence<Set<Element>>

Returns the concatenated elements of this sequence of sequences, inserting the given separator between each element.

func joined(separator: String) -> String

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

func split(separator: Element, maxSplits: Int, omittingEmptySubsequences: Bool) -> [Slice<Set<Element>>]

Returns the longest possible subsequences of the collection, in order, around elements equal to the given element.

func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator: (Element) -> Bool) -> [Slice<Set<Element>>]

Returns the longest possible subsequences of the collection, in order, that don’t contain elements satisfying the given predicate.