# Order Dependent Operations on Dictionary

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

## Topics

### Comparing Dictionaries

`func elementsEqual<OtherSequence>(OtherSequence, by: ((key: Key, value: Value), 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 starts<PossiblePrefix>(with: PossiblePrefix, by: ((key: Key, value: Value), 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.

`func lexicographicallyPrecedes<OtherSequence>(OtherSequence, by: ((key: Key, value: Value), (key: Key, value: Value)) -> 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.

### Manipulating Indices

`var startIndex: Dictionary<Key, Value>.Index`

The position of the first element in a nonempty dictionary.

`var endIndex: Dictionary<Key, Value>.Index`

The dictionary’s “past the end” position—that is, the position one greater than the last valid subscript argument.

`func index(Dictionary<Key, Value>.Index, offsetBy: Int) -> Dictionary<Key, Value>.Index`

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

`func index(Dictionary<Key, Value>.Index, offsetBy: Int, limitedBy: Dictionary<Key, Value>.Index) -> Dictionary<Key, Value>.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 Dictionary<Key, Value>.Index, offsetBy: Int, limitedBy: Dictionary<Key, Value>.Index) -> Bool`

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

`var indices: DefaultIndices<Dictionary<Key, Value>>`

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

### Selecting Elements

`subscript(Range<Dictionary<Key, Value>.Index>) -> Slice<Dictionary<Key, Value>>`

Accesses a contiguous subrange of the collection’s elements.

`subscript<R>(R) -> Slice<Dictionary<Key, Value>>`

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

`func prefix(Int) -> Slice<Dictionary<Key, Value>>`

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

`func prefix(through: Dictionary<Key, Value>.Index) -> Slice<Dictionary<Key, Value>>`

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

`func prefix(upTo: Dictionary<Key, Value>.Index) -> Slice<Dictionary<Key, Value>>`

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

`func prefix(while: ((key: Key, value: Value)) -> Bool) -> Slice<Dictionary<Key, Value>>`

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

`func suffix(Int) -> Slice<Dictionary<Key, Value>>`

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

`func suffix(from: Dictionary<Key, Value>.Index) -> Slice<Dictionary<Key, Value>>`

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

### Excluding Elements

`func dropFirst(Int) -> Slice<Dictionary<Key, Value>>`

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

`func drop(while: ((key: Key, value: Value)) -> Bool) -> Slice<Dictionary<Key, Value>>`

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

`func dropLast(Int) -> Slice<Dictionary<Key, Value>>`

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

`func popFirst() -> Dictionary<Key, Value>.Element?`

Removes and returns the first key-value pair of the dictionary if the dictionary isn’t empty.

### Transforming a Dictionary's Elements

`func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator: ((key: Key, value: Value)) -> Bool) -> [Slice<Dictionary<Key, Value>>]`

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

`func reversed() -> [(key: Key, value: Value)]`

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

`func withContiguousStorageIfAvailable<R>((UnsafeBufferPointer<(key: Key, value: Value)>) -> R) -> R?`

Call `body(p)`, where `p` is a pointer to the collection’s contiguous storage. If no such storage exists, it is first created. If the collection does not support an internal representation in a form of contiguous storage, `body` is not called and `nil` is returned.