Skip to content

[stdlib] Revert count(where:) #22289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ set(SWIFT_BENCH_MODULES
single-source/ClassArrayGetter
single-source/Codable
single-source/Combos
single-source/CountAlgo
single-source/DataBenchmarks
single-source/DeadArray
single-source/DictOfArraysToArrayOfDicts
Expand Down
127 changes: 0 additions & 127 deletions benchmark/single-source/CountAlgo.swift

This file was deleted.

2 changes: 0 additions & 2 deletions benchmark/utils/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import Chars
import ClassArrayGetter
import Codable
import Combos
import CountAlgo
import DataBenchmarks
import DeadArray
import DictOfArraysToArrayOfDicts
Expand Down Expand Up @@ -217,7 +216,6 @@ registerBenchmark(CharacterPropertiesPrecomputed)
registerBenchmark(Chars)
registerBenchmark(Codable)
registerBenchmark(Combos)
registerBenchmark(CountAlgo)
registerBenchmark(ClassArrayGetter)
registerBenchmark(DataBenchmarks)
registerBenchmark(DeadArray)
Expand Down
44 changes: 0 additions & 44 deletions stdlib/public/core/SequenceAlgorithms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -572,50 +572,6 @@ extension Sequence where Element : Equatable {
}
}

//===----------------------------------------------------------------------===//
// count(where:)
//===----------------------------------------------------------------------===//

extension Sequence {
/// Returns the number of elements in the sequence that satisfy the given
/// predicate.
///
/// You can use this method to count the number of elements that pass a test.
/// The following example finds the number of names that are fewer than
/// five characters long:
///
/// let names = ["Jacqueline", "Ian", "Amy", "Juan", "Soroush", "Tiffany"]
/// let shortNameCount = names.count(where: { $0.count < 5 })
/// // shortNameCount == 3
///
/// To find the number of times a specific element appears in the sequence,
/// use the equal to operator (`==`) in the closure to test for a match.
///
/// let birds = ["duck", "duck", "duck", "duck", "goose"]
/// let duckCount = birds.count(where: { $0 == "duck" })
/// // duckCount == 4
///
/// The sequence must be finite.
///
/// - Parameter predicate: A closure that takes each element of the sequence
/// as its argument and returns a Boolean value indicating whether
/// the element should be included in the count.
/// - Returns: The number of elements in the sequence that satisfy the given
/// predicate.
@inlinable
public func count(
where predicate: (Element) throws -> Bool
) rethrows -> Int {
var count = 0
for e in self {
if try predicate(e) {
count += 1
}
}
return count
}
}

//===----------------------------------------------------------------------===//
// reduce()
//===----------------------------------------------------------------------===//
Expand Down
2 changes: 2 additions & 0 deletions test/api-digester/Outputs/stability-stdlib-abi.swift.expected
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,5 @@ Subscript String.UnicodeScalarView.subscript(_:) has been removed
Subscript Substring.subscript(_:) has been removed

Func Collection.makeIterator() has self access kind changing from NonMutating to __Consuming

Func Sequence.count(where:) has been removed
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ Protocol SIMD has added inherited protocol Decodable
Protocol SIMD has added inherited protocol Encodable
Protocol SIMD has generic signature change from <Self : CustomStringConvertible, Self : ExpressibleByArrayLiteral, Self : Hashable, Self : SIMDStorage, Self.MaskStorage : SIMD, Self.MaskStorage.Scalar : FixedWidthInteger, Self.MaskStorage.Scalar : SignedInteger> to <Self : CustomStringConvertible, Self : Decodable, Self : Encodable, Self : ExpressibleByArrayLiteral, Self : Hashable, Self : SIMDStorage, Self.MaskStorage : SIMD, Self.MaskStorage.Scalar : FixedWidthInteger, Self.MaskStorage.Scalar : SignedInteger>
Protocol SIMDStorage has generic signature change from <Self.Scalar : Hashable> to <Self.Scalar : Decodable, Self.Scalar : Encodable, Self.Scalar : Hashable>

Func Sequence.count(where:) has been removed
15 changes: 0 additions & 15 deletions validation-test/stdlib/SequenceType.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -628,21 +628,6 @@ SequenceTypeTests.test("allSatisfy/Predicate") {
}
}

//===----------------------------------------------------------------------===//
// count(where:)
//===----------------------------------------------------------------------===//

SequenceTypeTests.test("count/Predicate") {
for test in predicateCountTests {
let s = MinimalSequence<OpaqueValue<Int>>(
elements: test.sequence.map { OpaqueValue($0) })
expectEqual(
test.expected,
s.count(where: { test.includeElement($0.value) }),
stackTrace: SourceLocStack().with(test.loc))
}
}

//===----------------------------------------------------------------------===//
// reduce()
//===----------------------------------------------------------------------===//
Expand Down