mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[stdlib] Add Sequence.Element, change ExpressibleByArrayLiteral.Element to ArrayLiteralElement (#8990)
* Give Sequence a top-level Element, constrain Iterator to match * Remove many instances of Iterator. * Fixed various hard-coded tests * XFAIL a few tests that need further investigation * Change assoc type for arrayLiteralConvertible * Mop up remaining "better expressed as a where clause" warnings * Fix UnicodeDecoders prototype test * Fix UIntBuffer * Fix hard-coded Element identifier in CSDiag * Fix up more tests * Account for flatMap changes
This commit is contained in:
@@ -759,7 +759,7 @@ public struct Set<Element : Hashable> :
|
||||
///
|
||||
/// - Parameter sequence: The elements to use as members of the new set.
|
||||
public init<Source : Sequence>(_ sequence: Source)
|
||||
where Source.Iterator.Element == Element {
|
||||
where Source.Element == Element {
|
||||
self.init(minimumCapacity: sequence.underestimatedCount)
|
||||
if let s = sequence as? Set<Element> {
|
||||
// If this sequence is actually a native `Set`, then we can quickly
|
||||
@@ -827,7 +827,7 @@ public struct Set<Element : Hashable> :
|
||||
/// otherwise, `false`.
|
||||
@_inlineable
|
||||
public func isSubset<S : Sequence>(of possibleSuperset: S) -> Bool
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
// FIXME(performance): isEmpty fast path, here and elsewhere.
|
||||
let other = Set(possibleSuperset)
|
||||
return isSubset(of: other)
|
||||
@@ -855,7 +855,7 @@ public struct Set<Element : Hashable> :
|
||||
/// `possibleStrictSuperset`; otherwise, `false`.
|
||||
@_inlineable
|
||||
public func isStrictSubset<S : Sequence>(of possibleStrictSuperset: S) -> Bool
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
// FIXME: code duplication.
|
||||
let other = Set(possibleStrictSuperset)
|
||||
return isStrictSubset(of: other)
|
||||
@@ -878,7 +878,7 @@ public struct Set<Element : Hashable> :
|
||||
/// otherwise, `false`.
|
||||
@_inlineable
|
||||
public func isSuperset<S : Sequence>(of possibleSubset: S) -> Bool
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
// FIXME(performance): Don't build a set; just ask if every element is in
|
||||
// `self`.
|
||||
let other = Set(possibleSubset)
|
||||
@@ -904,7 +904,7 @@ public struct Set<Element : Hashable> :
|
||||
/// - Returns: `true` if the set is a strict superset of
|
||||
/// `possibleStrictSubset`; otherwise, `false`.
|
||||
public func isStrictSuperset<S : Sequence>(of possibleStrictSubset: S) -> Bool
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
let other = Set(possibleStrictSubset)
|
||||
return other.isStrictSubset(of: self)
|
||||
}
|
||||
@@ -924,7 +924,7 @@ public struct Set<Element : Hashable> :
|
||||
/// - Returns: `true` if the set has no elements in common with `other`;
|
||||
/// otherwise, `false`.
|
||||
public func isDisjoint<S : Sequence>(with other: S) -> Bool
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
// FIXME(performance): Don't need to build a set.
|
||||
let otherSet = Set(other)
|
||||
return isDisjoint(with: otherSet)
|
||||
@@ -955,7 +955,7 @@ public struct Set<Element : Hashable> :
|
||||
/// - Returns: A new set with the unique elements of this set and `other`.
|
||||
@_inlineable
|
||||
public func union<S : Sequence>(_ other: S) -> Set<Element>
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
var newSet = self
|
||||
newSet.formUnion(other)
|
||||
return newSet
|
||||
@@ -976,7 +976,7 @@ public struct Set<Element : Hashable> :
|
||||
/// - Parameter other: A sequence of elements. `other` must be finite.
|
||||
@_inlineable
|
||||
public mutating func formUnion<S : Sequence>(_ other: S)
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
for item in other {
|
||||
insert(item)
|
||||
}
|
||||
@@ -998,13 +998,13 @@ public struct Set<Element : Hashable> :
|
||||
/// - Returns: A new set.
|
||||
@_inlineable
|
||||
public func subtracting<S : Sequence>(_ other: S) -> Set<Element>
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
return self._subtracting(other)
|
||||
}
|
||||
|
||||
@_versioned
|
||||
internal func _subtracting<S : Sequence>(_ other: S) -> Set<Element>
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
var newSet = self
|
||||
newSet.subtract(other)
|
||||
return newSet
|
||||
@@ -1024,12 +1024,12 @@ public struct Set<Element : Hashable> :
|
||||
///
|
||||
/// - Parameter other: A sequence of elements. `other` must be finite.
|
||||
public mutating func subtract<S : Sequence>(_ other: S)
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
_subtract(other)
|
||||
}
|
||||
|
||||
internal mutating func _subtract<S : Sequence>(_ other: S)
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
for item in other {
|
||||
remove(item)
|
||||
}
|
||||
@@ -1053,7 +1053,7 @@ public struct Set<Element : Hashable> :
|
||||
/// - Returns: A new set.
|
||||
@_inlineable
|
||||
public func intersection<S : Sequence>(_ other: S) -> Set<Element>
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
let otherSet = Set(other)
|
||||
return intersection(otherSet)
|
||||
}
|
||||
@@ -1073,7 +1073,7 @@ public struct Set<Element : Hashable> :
|
||||
/// - Parameter other: A sequence of elements. `other` must be finite.
|
||||
@_inlineable
|
||||
public mutating func formIntersection<S : Sequence>(_ other: S)
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
// Because `intersect` needs to both modify and iterate over
|
||||
// the left-hand side, the index may become invalidated during
|
||||
// traversal so an intermediate set must be created.
|
||||
@@ -1108,7 +1108,7 @@ public struct Set<Element : Hashable> :
|
||||
/// - Returns: A new set.
|
||||
@_inlineable
|
||||
public func symmetricDifference<S : Sequence>(_ other: S) -> Set<Element>
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
var newSet = self
|
||||
newSet.formSymmetricDifference(other)
|
||||
return newSet
|
||||
@@ -1133,7 +1133,7 @@ public struct Set<Element : Hashable> :
|
||||
/// - Parameter other: A sequence of elements. `other` must be finite.
|
||||
@_inlineable
|
||||
public mutating func formSymmetricDifference<S : Sequence>(_ other: S)
|
||||
where S.Iterator.Element == Element {
|
||||
where S.Element == Element {
|
||||
let otherSet = Set(other)
|
||||
formSymmetricDifference(otherSet)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user