Clarify endIndex behavior of partitioningIndex(where:) in documentation (Resolves #170) (#171)

The returned index isn’t necessarily an index of an element. In the case where it returns `endIndex`, it’s not valid for subscripting the collection.
This commit is contained in:
Matt Zanchelli authored and GitHub committed 2021-12-16 07:10:17 -06:00
1 parent 19c1d00177
commit da475ea9af
2 files changed
+24 -3

No files matched your search

+4 -3
View File
@@ -168,8 +168,8 @@ extension MutableCollection where Self: BidirectionalCollection {
//===----------------------------------------------------------------------===//
extension Collection {
/// Returns the index of the first element in the collection that matches
/// the predicate.
/// Returns the start index of the partition of a collection that matches
/// the given predicate.
///
/// The collection must already be partitioned according to the predicate.
/// That is, there should be an index `i` where for every element in
@@ -179,7 +179,8 @@ extension Collection {
/// - Parameter belongsInSecondPartition: A predicate that partitions the
/// collection.
/// - Returns: The index of the first element in the collection for which
/// `predicate` returns `true`.
/// `predicate` returns `true`, or `endIndex` if there are no elements
/// for which `predicate` returns `true`.
///
/// - Complexity: O(log *n*), where *n* is the length of this collection if
/// the collection conforms to `RandomAccessCollection`, otherwise O(*n*).