mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Revert "Name and label changes for closure parameters (for review only) (#2981)"
This reverts commit 18406900ba.
This commit is contained in:
@@ -21,10 +21,10 @@ orderingExplanation = """\
|
||||
/// is, for any elements `a`, `b`, and `c`, the following conditions must
|
||||
/// hold:
|
||||
///
|
||||
/// - `areInIncreasingOrder(a, a)` is always `false`. (Irreflexivity)
|
||||
/// - If `areInIncreasingOrder(a, b)` and `areInIncreasingOrder(b, c)` are
|
||||
/// both `true`, then `areInIncreasingOrder(a, c)` is also
|
||||
/// `true`. (Transitive comparability)
|
||||
/// - `isOrderedBefore(a, a)` is always `false`. (Irreflexivity)
|
||||
/// - If `isOrderedBefore(a, b)` and `isOrderedBefore(b, c)` are both `true`,
|
||||
/// then `isOrderedBefore(a, c)` is also `true`. (Transitive
|
||||
/// comparability)
|
||||
/// - Two elements are *incomparable* if neither is ordered before the other
|
||||
/// according to the predicate. If `a` and `b` are incomparable, and `b`
|
||||
/// and `c` are incomparable, then `a` and `c` are also incomparable.
|
||||
@@ -36,10 +36,10 @@ equivalenceExplanation = """\
|
||||
/// is, for any elements `a`, `b`, and `c`, the following conditions must
|
||||
/// hold:
|
||||
///
|
||||
/// - `areEquivalent(a, a)` is always `true`. (Reflexivity)
|
||||
/// - `areEquivalent(a, b)` implies `areEquivalent(b, a)`. (Symmetry)
|
||||
/// - If `areEquivalent(a, b)` and `areEquivalent(b, c)` are both `true`, then
|
||||
/// `areEquivalent(a, c)` is also `true`. (Transitivity)
|
||||
/// - `isEquivalent(a, a)` is always `true`. (Reflexivity)
|
||||
/// - `isEquivalent(a, b)` implies `isEquivalent(b, a)`. (Symmetry)
|
||||
/// - If `isEquivalent(a, b)` and `isEquivalent(b, c)` are both `true`, then
|
||||
/// `isEquivalent(a, c)` is also `true`. (Transitivity)
|
||||
///"""
|
||||
|
||||
}%
|
||||
@@ -87,7 +87,7 @@ extension Sequence ${"" if preds else "where Iterator.Element : Comparable"} {
|
||||
/// the comparison between elements.
|
||||
///
|
||||
${orderingExplanation}
|
||||
/// This example shows how to use the `min(by:)` method on a
|
||||
/// This example shows how to use the `min(isOrderedBefore:)` method on a
|
||||
/// dictionary to find the key-value pair with the lowest value.
|
||||
///
|
||||
/// let hues = ["Heliotrope": 296, "Coral": 16, "Aquamarine": 156]
|
||||
@@ -95,12 +95,11 @@ ${orderingExplanation}
|
||||
/// print(leastHue)
|
||||
/// // Prints "Optional(("Coral", 16))"
|
||||
///
|
||||
/// - Parameter areInIncreasingOrder: A predicate that returns `true`
|
||||
/// if its first argument should be ordered before its second
|
||||
/// argument; otherwise, `false`.
|
||||
/// - Parameter isOrderedBefore: A predicate that returns `true` if its first
|
||||
/// argument should be ordered before its second argument; otherwise,
|
||||
/// `false`.
|
||||
/// - Returns: The sequence's minimum element, according to
|
||||
/// `areInIncreasingOrder`. If the sequence has no elements, returns
|
||||
/// `nil`.
|
||||
/// `isOrderedBefore`. If the sequence has no elements, returns `nil`.
|
||||
///
|
||||
/// - SeeAlso: `min()`
|
||||
% else:
|
||||
@@ -116,19 +115,19 @@ ${orderingExplanation}
|
||||
/// - Returns: The sequence's minimum element. If the sequence has no
|
||||
/// elements, returns `nil`.
|
||||
///
|
||||
/// - SeeAlso: `min(by:)`
|
||||
/// - SeeAlso: `min(isOrderedBefore:)`
|
||||
% end
|
||||
@warn_unqualified_access
|
||||
public func min(
|
||||
% if preds:
|
||||
by areInIncreasingOrder: @noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
isOrderedBefore: @noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
% end
|
||||
) ${rethrows_}-> ${GElement}? {
|
||||
var it = makeIterator()
|
||||
guard var result = it.next() else { return nil }
|
||||
for e in IteratorSequence(it) {
|
||||
% if preds:
|
||||
if try areInIncreasingOrder(e, result) { result = e }
|
||||
if try isOrderedBefore(e, result) { result = e }
|
||||
% else:
|
||||
if e < result { result = e }
|
||||
% end
|
||||
@@ -141,7 +140,7 @@ ${orderingExplanation}
|
||||
/// as the comparison between elements.
|
||||
///
|
||||
${orderingExplanation}
|
||||
/// This example shows how to use the `max(by:)` method on a
|
||||
/// This example shows how to use the `max(isOrderedBefore:)` method on a
|
||||
/// dictionary to find the key-value pair with the highest value.
|
||||
///
|
||||
/// let hues = ["Heliotrope": 296, "Coral": 16, "Aquamarine": 156]
|
||||
@@ -149,7 +148,7 @@ ${orderingExplanation}
|
||||
/// print(greatestHue)
|
||||
/// // Prints "Optional(("Heliotrope", 296))"
|
||||
///
|
||||
/// - Parameter areInIncreasingOrder: A predicate that returns `true` if its
|
||||
/// - Parameter isOrderedBefore: A predicate that returns `true` if its
|
||||
/// first argument should be ordered before its second argument;
|
||||
/// otherwise, `false`.
|
||||
/// - Returns: The sequence's maximum element if the sequence is not empty;
|
||||
@@ -169,19 +168,19 @@ ${orderingExplanation}
|
||||
/// - Returns: The sequence's maximum element. If the sequence has no
|
||||
/// elements, returns `nil`.
|
||||
///
|
||||
/// - SeeAlso: `max(by:)`
|
||||
/// - SeeAlso: `max(isOrderedBefore:)`
|
||||
% end
|
||||
@warn_unqualified_access
|
||||
public func max(
|
||||
% if preds:
|
||||
by areInIncreasingOrder: @noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
isOrderedBefore: @noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
% end
|
||||
) ${rethrows_}-> ${GElement}? {
|
||||
var it = makeIterator()
|
||||
guard var result = it.next() else { return nil }
|
||||
for e in IteratorSequence(it) {
|
||||
% if preds:
|
||||
if try areInIncreasingOrder(result, e) { result = e }
|
||||
if try isOrderedBefore(result, e) { result = e }
|
||||
% else:
|
||||
if e > result { result = e }
|
||||
% end
|
||||
@@ -211,7 +210,7 @@ extension Sequence ${"" if preds else "where Iterator.Element : Equatable"} {
|
||||
${equivalenceExplanation}
|
||||
/// - Parameters:
|
||||
/// - possiblePrefix: A sequence to compare to this sequence.
|
||||
/// - areEquivalent: A predicate that returns `true` if its two arguments
|
||||
/// - isEquivalent: A predicate that returns `true` if its two arguments
|
||||
/// are equivalent; otherwise, `false`.
|
||||
/// - Returns: `true` if the initial elements of the sequence are equivalent
|
||||
/// to the elements of `possiblePrefix`; otherwise, `false`. Returns
|
||||
@@ -237,12 +236,12 @@ ${equivalenceExplanation}
|
||||
/// the elements of `possiblePrefix`; otherwise, `false`. Returns `true`
|
||||
/// if `possiblePrefix` has no elements.
|
||||
///
|
||||
/// - SeeAlso: `starts(with:by:)`
|
||||
/// - SeeAlso: `starts(with:isEquivalent:)`
|
||||
% end
|
||||
public func starts<PossiblePrefix>(
|
||||
with possiblePrefix: PossiblePrefix${"," if preds else ""}
|
||||
% if preds:
|
||||
by areEquivalent: @noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
isEquivalent: @noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
% end
|
||||
) ${rethrows_}-> Bool
|
||||
where
|
||||
@@ -252,7 +251,7 @@ ${equivalenceExplanation}
|
||||
var possiblePrefixIterator = possiblePrefix.makeIterator()
|
||||
for e0 in self {
|
||||
if let e1 = possiblePrefixIterator.next() {
|
||||
if ${"try !areEquivalent(e0, e1)" if preds else "e0 != e1"} {
|
||||
if ${"try !isEquivalent(e0, e1)" if preds else "e0 != e1"} {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -287,10 +286,10 @@ extension Sequence ${"" if preds else "where Iterator.Element : Equatable"} {
|
||||
${equivalenceExplanation}
|
||||
/// - Parameters:
|
||||
/// - other: A sequence to compare to this sequence.
|
||||
/// - areEquivalent: A predicate that returns `true` if its two arguments
|
||||
/// - isEquivalent: A predicate that returns `true` if its two arguments
|
||||
/// are equivalent; otherwise, `false`.
|
||||
/// - Returns: `true` if this sequence and `other` contain equivalent items,
|
||||
/// using `areEquivalent` as the equivalence test; otherwise, `false.`
|
||||
/// using `isEquivalent` as the equivalence test; otherwise, `false.`
|
||||
///
|
||||
/// - SeeAlso: `elementsEqual(_:)`
|
||||
% else:
|
||||
@@ -313,12 +312,12 @@ ${equivalenceExplanation}
|
||||
/// - Returns: `true` if this sequence and `other` contain the same elements
|
||||
/// in the same order.
|
||||
///
|
||||
/// - SeeAlso: `elementsEqual(_:by:)`
|
||||
/// - SeeAlso: `elementsEqual(_:isEquivalent:)`
|
||||
% end
|
||||
public func elementsEqual<OtherSequence>(
|
||||
_ other: OtherSequence${"," if preds else ""}
|
||||
% if preds:
|
||||
by areEquivalent: @noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
isEquivalent: @noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
% end
|
||||
) ${rethrows_}-> Bool
|
||||
where
|
||||
@@ -330,7 +329,7 @@ ${equivalenceExplanation}
|
||||
while true {
|
||||
switch (iter1.next(), iter2.next()) {
|
||||
case let (e1?, e2?):
|
||||
if ${'try !areEquivalent(e1, e2)' if preds else 'e1 != e2'} {
|
||||
if ${'try !isEquivalent(e1, e2)' if preds else 'e1 != e2'} {
|
||||
return false
|
||||
}
|
||||
case (_?, nil),
|
||||
@@ -364,11 +363,11 @@ extension Sequence ${"" if preds else "where Iterator.Element : Comparable"} {
|
||||
${orderingExplanation}
|
||||
/// - Parameters:
|
||||
/// - other: A sequence to compare to this sequence.
|
||||
/// - areInIncreasingOrder: A predicate that returns `true` if its first
|
||||
/// - isOrderedBefore: A predicate that returns `true` if its first
|
||||
/// argument should be ordered before its second argument; otherwise,
|
||||
/// `false`.
|
||||
/// - Returns: `true` if this sequence precedes `other` in a dictionary
|
||||
/// ordering as ordered by `areInIncreasingOrder`; otherwise, `false`.
|
||||
/// ordering as ordered by `isOrderedBefore`; otherwise, `false`.
|
||||
///
|
||||
/// - Note: This method implements the mathematical notion of lexicographical
|
||||
/// ordering, which has no connection to Unicode. If you are sorting
|
||||
@@ -398,13 +397,12 @@ ${orderingExplanation}
|
||||
/// ordering, which has no connection to Unicode. If you are sorting
|
||||
/// strings to present to the end user, you should use `String` APIs that
|
||||
/// perform localized comparison.
|
||||
/// - SeeAlso: `lexicographicallyPrecedes(_:by:)`
|
||||
/// - SeeAlso: `lexicographicallyPrecedes(_:isOrderedBefore:)`
|
||||
% end
|
||||
public func lexicographicallyPrecedes<OtherSequence>(
|
||||
_ other: OtherSequence${"," if preds else ""}
|
||||
% if preds:
|
||||
by areInIncreasingOrder:
|
||||
@noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
isOrderedBefore: @noescape (${GElement}, ${GElement}) throws -> Bool
|
||||
% end
|
||||
) ${rethrows_}-> Bool
|
||||
where
|
||||
@@ -416,10 +414,10 @@ ${orderingExplanation}
|
||||
while true {
|
||||
if let e1 = iter1.next() {
|
||||
if let e2 = iter2.next() {
|
||||
if ${"try areInIncreasingOrder(e1, e2)" if preds else "e1 < e2"} {
|
||||
if ${"try isOrderedBefore(e1, e2)" if preds else "e1 < e2"} {
|
||||
return true
|
||||
}
|
||||
if ${"try areInIncreasingOrder(e2, e1)" if preds else "e2 < e1"} {
|
||||
if ${"try isOrderedBefore(e2, e1)" if preds else "e2 < e1"} {
|
||||
return false
|
||||
}
|
||||
continue // Equivalent
|
||||
@@ -505,7 +503,7 @@ extension Sequence {
|
||||
/// - Returns: `true` if the sequence contains an element that satisfies
|
||||
/// `predicate`; otherwise, `false`.
|
||||
public func contains(
|
||||
where predicate: @noescape (${GElement}) throws -> Bool
|
||||
_ predicate: @noescape (${GElement}) throws -> Bool
|
||||
) rethrows -> Bool {
|
||||
for e in self {
|
||||
if try predicate(e) {
|
||||
@@ -524,44 +522,40 @@ extension Sequence {
|
||||
/// Returns the result of calling the given combining closure with each
|
||||
/// element of this sequence and an accumulating value.
|
||||
///
|
||||
/// The `nextPartialResult` closure is called sequentially with an
|
||||
/// accumulating value initialized to `initialResult` and each
|
||||
/// element of the sequence. This example shows how to find the sum
|
||||
/// of an array of numbers.
|
||||
/// The `combine` closure is called sequentially with an accumulating
|
||||
/// value initialized to `initial` and each element of the sequence. This
|
||||
/// example shows how to find the sum of an array of numbers.
|
||||
///
|
||||
/// let numbers = [1, 2, 3, 4]
|
||||
/// let addTwo: (Int, Int) -> Int = { x, y in x + y }
|
||||
/// let numberSum = numbers.reduce(0, addTwo)
|
||||
/// let numberSum = numbers.reduce(0, combine: addTwo)
|
||||
/// // 'numberSum' == 10
|
||||
///
|
||||
/// When `numbers.reduce(_:_:)` is called, the
|
||||
/// following steps occur:
|
||||
/// When `numbers.reduce(_:combine:)` is called, the following steps
|
||||
/// occur:
|
||||
///
|
||||
/// 1. The `nextPartialResult` closure is called with the initial
|
||||
/// result and the first element of `numbers`, returning the sum:
|
||||
/// `1`.
|
||||
/// 1. The `combine` closure is called with the initial value and the
|
||||
/// first element of `numbers`, returning the sum: `1`.
|
||||
/// 2. The closure is called again repeatedly with the previous call's
|
||||
/// return value and each element of the sequence.
|
||||
/// 3. When the sequence is exhausted, the last value returned from the
|
||||
/// closure is returned to the caller.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - initialResult: the initial accumulating value.
|
||||
/// - nextPartialResult: A closure that combines an accumulating
|
||||
/// value and an element of the sequence into a new accumulating
|
||||
/// value, to be used in the next call of the
|
||||
/// `nextPartialResult` closure or returned to the caller.
|
||||
/// - Returns: The final accumulated value.
|
||||
public func reduce<Result>(
|
||||
_ initialResult: Result,
|
||||
_ nextPartialResult:
|
||||
@noescape (partialResult: Result, ${GElement}) throws -> Result
|
||||
) rethrows -> Result {
|
||||
var accumulator = initialResult
|
||||
/// - initial: A value to use as the initial value for accumulation.
|
||||
/// - combine: A closure that combines an accumulating value and an
|
||||
/// element of the sequence into a new accumulating value, to be used
|
||||
/// in the next call of the `combine` closure or returned to the
|
||||
/// caller.
|
||||
/// - Returns: The final accumulated value.
|
||||
public func reduce<T>(
|
||||
_ initial: T, combine: @noescape (T, ${GElement}) throws -> T
|
||||
) rethrows -> T {
|
||||
var result = initial
|
||||
for element in self {
|
||||
accumulator = try nextPartialResult(partialResult: accumulator, element)
|
||||
result = try combine(result, element)
|
||||
}
|
||||
return accumulator
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -679,14 +673,14 @@ extension Sequence {
|
||||
Builtin.unreachable()
|
||||
}
|
||||
|
||||
@available(*, unavailable, renamed: "min(by:)")
|
||||
@available(*, unavailable, renamed: "min(isOrderedBefore:)")
|
||||
public func minElement(
|
||||
_ isOrderedBefore: @noescape (Iterator.Element, Iterator.Element) throws -> Bool
|
||||
) rethrows -> Iterator.Element? {
|
||||
Builtin.unreachable()
|
||||
}
|
||||
|
||||
@available(*, unavailable, renamed: "max(by:)")
|
||||
@available(*, unavailable, renamed: "max(isOrderedBefore:)")
|
||||
public func maxElement(
|
||||
_ isOrderedBefore: @noescape (Iterator.Element, Iterator.Element) throws -> Bool
|
||||
) rethrows -> Iterator.Element? {
|
||||
@@ -698,7 +692,7 @@ extension Sequence {
|
||||
Builtin.unreachable()
|
||||
}
|
||||
|
||||
@available(*, unavailable, renamed: "starts(with:by:)")
|
||||
@available(*, unavailable, renamed: "starts(with:isEquivalent:)")
|
||||
public func startsWith<PossiblePrefix>(
|
||||
_ possiblePrefix: PossiblePrefix,
|
||||
isEquivalent: @noescape (Iterator.Element, Iterator.Element) throws -> Bool
|
||||
@@ -709,7 +703,7 @@ extension Sequence {
|
||||
Builtin.unreachable()
|
||||
}
|
||||
|
||||
@available(*, unavailable, renamed: "lexicographicallyPrecedes(_:by:)")
|
||||
@available(*, unavailable, renamed: "lexicographicallyPrecedes(_:isOrderedBefore:)")
|
||||
public func lexicographicalCompare<
|
||||
OtherSequence
|
||||
>(
|
||||
|
||||
Reference in New Issue
Block a user