mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[stdlib] any/all algorithms, keyword for contains
Expose any, all on Array and all the Lazy sequence adapters. Make the 'contains' algorithm that takes a predecate unavailable in favor of 'any', which does the same thing. Fixes <rdar://problem/18190149> [algorithm] `contains` syntax is ambiguous Swift SVN r21810
This commit is contained in:
@@ -348,8 +348,16 @@ public func lexicographicalCompare<
|
||||
}
|
||||
|
||||
/// Return `true` iff an element in `seq` satisfies `predicate`.
|
||||
@availability(*, unavailable, renamed="any")
|
||||
public func contains<
|
||||
S: SequenceType, L: BooleanType
|
||||
>(seq: S, predicate: (S.Generator.Element)->L) -> Bool {
|
||||
return any(seq, predicate)
|
||||
}
|
||||
|
||||
/// Return `true` iff an element in `seq` satisfies `predicate`.
|
||||
public func any<
|
||||
S: SequenceType, L: BooleanType
|
||||
>(seq: S, predicate: (S.Generator.Element)->L) -> Bool {
|
||||
for a in seq {
|
||||
if predicate(a) {
|
||||
@@ -359,11 +367,18 @@ public func contains<
|
||||
return false
|
||||
}
|
||||
|
||||
/// Return `true` iff all elements in `seq` satisfy `predicate`.
|
||||
public func all<
|
||||
S: SequenceType, L: BooleanType
|
||||
>(seq: S, predicate: (S.Generator.Element)->L) -> Bool {
|
||||
return !any(seq) { !predicate($0) }
|
||||
}
|
||||
|
||||
/// Return `true` iff `x` is in `seq`.
|
||||
public func contains<
|
||||
S: SequenceType where S.Generator.Element: Equatable
|
||||
>(seq: S, x: S.Generator.Element) -> Bool {
|
||||
return contains(seq, { $0 == x })
|
||||
>(seq: S, element x: S.Generator.Element) -> Bool {
|
||||
return any(seq, { $0 == x })
|
||||
}
|
||||
|
||||
/// Return the result of repeatedly calling `combine` with an
|
||||
|
||||
Reference in New Issue
Block a user