Skip to content

Commit dcbfdb5

Browse files
author
Dave Abrahams
committed
_ includeElement/whereElementsSatisfy predicate => _ isIncluded
1 parent 014b697 commit dcbfdb5

File tree

10 files changed

+52
-52
lines changed

10 files changed

+52
-52
lines changed

stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ public struct ${Self}<
229229
}
230230

231231
public func filter(
232-
_ includeElement: @noescape (Base.Iterator.Element) throws -> Bool
232+
_ isIncluded: @noescape (Base.Iterator.Element) throws -> Bool
233233
) rethrows -> [Base.Iterator.Element] {
234234
Log.filter[selfType] += 1
235-
return try base.filter(includeElement)
235+
return try base.filter(isIncluded)
236236
}
237237

238238
public func forEach(

stdlib/public/core/ExistentialCollection.swift.gyb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ internal class _AnyRandomAccessCollectionBox<Element>
147147
}
148148

149149
internal func _filter(
150-
_ includeElement: @noescape (Element) throws -> Bool
150+
_ isIncluded: @noescape (Element) throws -> Bool
151151
) rethrows -> [Element] {
152152
_abstract()
153153
}
@@ -335,9 +335,9 @@ internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Iterator.Elemen
335335
return try _base.map(transform)
336336
}
337337
internal override func _filter(
338-
_ includeElement: @noescape (Element) throws -> Bool
338+
_ isIncluded: @noescape (Element) throws -> Bool
339339
) rethrows -> [Element] {
340-
return try _base.filter(includeElement)
340+
return try _base.filter(isIncluded)
341341
}
342342
internal override func _forEach(
343343
_ body: @noescape (Element) throws -> Void
@@ -579,9 +579,9 @@ extension Any${Kind} {
579579
}
580580

581581
public func filter(
582-
_ includeElement: @noescape (Element) throws -> Bool
582+
_ isIncluded: @noescape (Element) throws -> Bool
583583
) rethrows -> [Element] {
584-
return try _box._filter(includeElement)
584+
return try _box._filter(isIncluded)
585585
}
586586

587587
public func forEach(

stdlib/public/core/Filter.swift.gyb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ public struct LazyFilterIterator<
4343
}
4444

4545
/// Creates an instance that produces the elements `x` of `base`
46-
/// for which `predicate(x) == true`.
46+
/// for which `isIncluded(x) == true`.
4747
internal init(
4848
_base: Base,
49-
whereElementsSatisfy predicate: (Base.Element) -> Bool
49+
_ isIncluded: (Base.Element) -> Bool
5050
) {
5151
self._base = _base
52-
self._predicate = predicate
52+
self._predicate = isIncluded
5353
}
5454

5555
/// The underlying iterator whose elements are being filtered.
@@ -75,18 +75,18 @@ public struct LazyFilterSequence<Base : Sequence>
7575
/// - Complexity: O(1).
7676
public func makeIterator() -> LazyFilterIterator<Base.Iterator> {
7777
return LazyFilterIterator(
78-
_base: base.makeIterator(), whereElementsSatisfy: _include)
78+
_base: base.makeIterator(), _include)
7979
}
8080

8181
/// Creates an instance consisting of the elements `x` of `base` for
82-
/// which `predicate(x) == true`.
82+
/// which `isIncluded(x) == true`.
8383
public // @testable
8484
init(
8585
_base base: Base,
86-
whereElementsSatisfy predicate: (Base.Iterator.Element) -> Bool
86+
_ isIncluded: (Base.Iterator.Element) -> Bool
8787
) {
8888
self.base = base
89-
self._include = predicate
89+
self._include = isIncluded
9090
}
9191

9292
/// The underlying sequence whose elements are being filtered
@@ -186,14 +186,14 @@ public struct ${Self}<
186186
public typealias IndexDistance = Base.IndexDistance
187187

188188
/// Construct an instance containing the elements of `base` that
189-
/// satisfy `predicate`.
189+
/// satisfy `isIncluded`.
190190
public // @testable
191191
init(
192192
_base: Base,
193-
whereElementsSatisfy predicate: (Base.Iterator.Element) -> Bool
193+
_ isIncluded: (Base.Iterator.Element) -> Bool
194194
) {
195195
self._base = _base
196-
self._predicate = predicate
196+
self._predicate = isIncluded
197197
}
198198

199199
/// The position of the first element in a non-empty collection.
@@ -281,7 +281,7 @@ public struct ${Self}<
281281
/// - Complexity: O(1).
282282
public func makeIterator() -> LazyFilterIterator<Base.Iterator> {
283283
return LazyFilterIterator(
284-
_base: _base.makeIterator(), whereElementsSatisfy: _predicate)
284+
_base: _base.makeIterator(), _predicate)
285285
}
286286

287287
var _base: Base
@@ -291,17 +291,17 @@ public struct ${Self}<
291291
% end
292292

293293
extension LazySequenceProtocol {
294-
/// Returns the elements of `self` that satisfy `predicate`.
294+
/// Returns the elements of `self` that satisfy `isIncluded`.
295295
///
296296
/// - Note: The elements of the result are computed on-demand, as
297297
/// the result is used. No buffering storage is allocated and each
298298
/// traversal step invokes `predicate` on one or more underlying
299299
/// elements.
300300
public func filter(
301-
_ predicate: (Elements.Iterator.Element) -> Bool
301+
_ isIncluded: (Elements.Iterator.Element) -> Bool
302302
) -> LazyFilterSequence<Self.Elements> {
303303
return LazyFilterSequence(
304-
_base: self.elements, whereElementsSatisfy: predicate)
304+
_base: self.elements, isIncluded)
305305
}
306306
}
307307

@@ -319,10 +319,10 @@ extension LazyCollectionProtocol
319319
/// traversal step invokes `predicate` on one or more underlying
320320
/// elements.
321321
public func filter(
322-
_ predicate: (Elements.Iterator.Element) -> Bool
322+
_ isIncluded: (Elements.Iterator.Element) -> Bool
323323
) -> LazyFilter${collectionForTraversal(Traversal)}<Self.Elements> {
324324
return LazyFilter${collectionForTraversal(Traversal)}(
325-
_base: self.elements, whereElementsSatisfy: predicate)
325+
_base: self.elements, isIncluded)
326326
}
327327
}
328328

stdlib/public/core/Sequence.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,12 @@ public protocol Sequence {
387387
/// print(shortNames)
388388
/// // Prints "["Kim", "Karl"]"
389389
///
390-
/// - Parameter includeElement: A closure that takes an element of the
390+
/// - Parameter isIncluded: A closure that takes an element of the
391391
/// sequence as its argument and returns a Boolean value indicating
392392
/// whether the element should be included in the returned array.
393393
/// - Returns: An array of the elements that `includeElement` allowed.
394394
func filter(
395-
_ includeElement: @noescape (Iterator.Element) throws -> Bool
395+
_ isIncluded: @noescape (Iterator.Element) throws -> Bool
396396
) rethrows -> [Iterator.Element]
397397

398398
/// Calls the given closure on each element in the sequence in the same order
@@ -747,20 +747,20 @@ extension Sequence {
747747
/// print(shortNames)
748748
/// // Prints "["Kim", "Karl"]"
749749
///
750-
/// - Parameter includeElement: A closure that takes an element of the
750+
/// - Parameter shouldInclude: A closure that takes an element of the
751751
/// sequence as its argument and returns a Boolean value indicating
752752
/// whether the element should be included in the returned array.
753753
/// - Returns: An array of the elements that `includeElement` allowed.
754754
public func filter(
755-
_ includeElement: @noescape (Iterator.Element) throws -> Bool
755+
_ isIncluded: @noescape (Iterator.Element) throws -> Bool
756756
) rethrows -> [Iterator.Element] {
757757

758758
var result = ContiguousArray<Iterator.Element>()
759759

760760
var iterator = self.makeIterator()
761761

762762
while let element = iterator.next() {
763-
if try includeElement(element) {
763+
if try isIncluded(element) {
764764
result.append(element)
765765
}
766766
}

stdlib/public/core/SequenceWrapper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ extension Sequence
8888
/// whether the element should be included in the returned array.
8989
/// - Returns: An array of the elements that `includeElement` allowed.
9090
public func filter(
91-
_ includeElement: @noescape (Base.Iterator.Element) throws -> Bool
91+
_ isIncluded: @noescape (Base.Iterator.Element) throws -> Bool
9292
) rethrows -> [Base.Iterator.Element] {
93-
return try _base.filter(includeElement)
93+
return try _base.filter(isIncluded)
9494
}
9595

9696
public func _customContainsEquatableElement(

test/Prototypes/CollectionTransformers.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ internal class _CollectionTransformerStep<PipelineInputElement_, OutputElement_>
859859
fatalError("abstract method")
860860
}
861861

862-
func filter(_ predicate: (OutputElement) -> Bool)
862+
func filter(_ isIncluded: (OutputElement) -> Bool)
863863
-> _CollectionTransformerStep<PipelineInputElement, OutputElement> {
864864

865865
fatalError("abstract method")
@@ -911,11 +911,11 @@ final internal class _CollectionTransformerStepCollectionSource<
911911
}
912912
}
913913

914-
override func filter(_ predicate: (InputElement) -> Bool)
914+
override func filter(_ isIncluded: (InputElement) -> Bool)
915915
-> _CollectionTransformerStep<PipelineInputElement, InputElement> {
916916

917917
return _CollectionTransformerStepOneToMaybeOne(self) {
918-
predicate($0) ? $0 : nil
918+
isIncluded($0) ? $0 : nil
919919
}
920920
}
921921

@@ -990,15 +990,15 @@ final internal class _CollectionTransformerStepOneToMaybeOne<
990990
}
991991
}
992992

993-
override func filter(_ predicate: (OutputElement) -> Bool)
993+
override func filter(_ isIncluded: (OutputElement) -> Bool)
994994
-> _CollectionTransformerStep<PipelineInputElement, OutputElement> {
995995

996996
// Let the closure below capture only one variable, not the whole `self`.
997997
let localTransform = _transform
998998
return _CollectionTransformerStepOneToMaybeOne<PipelineInputElement, OutputElement, InputStep>(_input) {
999999
(input: InputElement) -> OutputElement? in
10001000
if let e = localTransform(input) {
1001-
return predicate(e) ? e : nil
1001+
return isIncluded(e) ? e : nil
10021002
}
10031003
return nil
10041004
}
@@ -1265,12 +1265,12 @@ public struct CollectionTransformerPipeline<
12651265
)
12661266
}
12671267

1268-
public func filter(_ predicate: (T) -> Bool)
1268+
public func filter(_ isIncluded: (T) -> Bool)
12691269
-> CollectionTransformerPipeline<InputCollection, T> {
12701270

12711271
return CollectionTransformerPipeline<InputCollection, T>(
12721272
_input: _input,
1273-
_step: _step.filter(predicate)
1273+
_step: _step.filter(isIncluded)
12741274
)
12751275
}
12761276

validation-test/compiler_crashers_2_fixed/0020-rdar21598514.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ extension LoggingSequenceType {
116116
}
117117

118118
public func filter(
119-
@noescape includeElement: (Base.Iterator.Element) -> Bool
119+
@noescape isIncluded: (Base.Iterator.Element) -> Bool
120120
) -> [Base.Iterator.Element] {
121121
++SequenceLog.filter[selfType]
122-
return base.filter(includeElement)
122+
return base.filter(isIncluded)
123123
}
124124

125125
public func _customContainsEquatableElement(

validation-test/compiler_crashers_2_fixed/0022-rdar21625478.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public protocol MySequence {
2424
) -> [T]
2525

2626
func filter(
27-
_ includeElement: @noescape (Iterator.Element) -> Bool
27+
_ isIncluded: @noescape (Iterator.Element) -> Bool
2828
) -> [Iterator.Element]
2929

3030
func _customContainsEquatableElement(
@@ -54,7 +54,7 @@ extension MySequence {
5454
}
5555

5656
public func filter(
57-
_ includeElement: @noescape (Iterator.Element) -> Bool
57+
_ isIncluded: @noescape (Iterator.Element) -> Bool
5858
) -> [Iterator.Element] {
5959
return []
6060
}
@@ -256,10 +256,10 @@ extension LoggingSequenceType
256256
}
257257

258258
public func filter(
259-
_ includeElement: @noescape (Base.Iterator.Element) -> Bool
259+
_ isIncluded: @noescape (Base.Iterator.Element) -> Bool
260260
) -> [Base.Iterator.Element] {
261261
Log.filter[selfType] += 1
262-
return base.filter(includeElement)
262+
return base.filter(isIncluded)
263263
}
264264

265265
public func _customContainsEquatableElement(

validation-test/stdlib/CollectionType.swift.gyb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ struct MinimalCollectionWith${Implementation}Filter<Element>
105105
}
106106

107107
func filter(
108-
_ transform: @noescape (Element) throws -> Bool
108+
_ isIncluded: @noescape (Element) throws -> Bool
109109
) rethrows -> [Element] {
110110
MinimalCollectionWithCustomFilter.timesFilterWasCalled += 1
111-
return try _data.filter(transform)
111+
return try _data.filter(isIncluded)
112112
}
113113

114114
% end
@@ -119,27 +119,27 @@ struct MinimalCollectionWith${Implementation}Filter<Element>
119119

120120
func callStaticCollectionFilter(
121121
_ sequence: MinimalCollectionWithDefaultFilter<OpaqueValue<Int>>,
122-
includeElement: @noescape (OpaqueValue<Int>) -> Bool
122+
_ isIncluded: @noescape (OpaqueValue<Int>) -> Bool
123123
) -> [OpaqueValue<Int>] {
124-
var result = sequence.filter(includeElement)
124+
var result = sequence.filter(isIncluded)
125125
expectType([OpaqueValue<Int>].self, &result)
126126
return result
127127
}
128128

129129
func callStaticCollectionFilter(
130130
_ sequence: MinimalCollectionWithCustomFilter<OpaqueValue<Int>>,
131-
includeElement: @noescape (OpaqueValue<Int>) -> Bool
131+
_ isIncluded: @noescape (OpaqueValue<Int>) -> Bool
132132
) -> [OpaqueValue<Int>] {
133-
var result = sequence.filter(includeElement)
133+
var result = sequence.filter(isIncluded)
134134
expectType([OpaqueValue<Int>].self, &result)
135135
return result
136136
}
137137

138138
func callGenericCollectionFilter<S : Collection>(
139139
_ sequence: S,
140-
includeElement: @noescape (S.Iterator.Element) -> Bool
140+
_ isIncluded: @noescape (S.Iterator.Element) -> Bool
141141
) -> [S.Iterator.Element] {
142-
var result = sequence.filter(includeElement)
142+
var result = sequence.filter(isIncluded)
143143
expectType(Array<S.Iterator.Element>.self, &result)
144144
return result
145145
}

validation-test/stdlib/Lazy.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ tests.test("LazyFilterSequence") {
10571057
// Try again using explicit construction
10581058
filtered = LazyFilterSequence(
10591059
_base: MinimalSequence(elements: base),
1060-
whereElementsSatisfy: { x in calls += 1; return x.value % 2 == 0})
1060+
{ x in calls += 1; return x.value % 2 == 0})
10611061

10621062
expectEqual(100, calls)
10631063

0 commit comments

Comments
 (0)