Skip to content

Commit 8f54eb0

Browse files
author
Dave Abrahams
committed
elementTransform => transformation
"element" just repeats type information and we haven't done anything like that with any of the other closures.
1 parent 08b828b commit 8f54eb0

16 files changed

+92
-92
lines changed

stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ public func withInvalidOrderings(invoke body: ((Int, Int) -> Bool) -> Void) {
6060

6161
internal func _mapInPlace<C : MutableCollection>(
6262
_ elements: inout C,
63-
_ elementTransform: @noescape (C.Iterator.Element) -> C.Iterator.Element
63+
_ transformation: @noescape (C.Iterator.Element) -> C.Iterator.Element
6464
) where C.Indices.Iterator.Element == C.Index {
6565
for i in elements.indices {
66-
elements[i] = elementTransform(elements[i])
66+
elements[i] = transformation(elements[i])
6767
}
6868
}
6969

stdlib/private/StdlibCollectionUnittest/CheckSequenceType.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ public struct FlatMapToOptionalTest {
164164
public init(
165165
_ expected: [Int32],
166166
_ sequence: [Int],
167-
_ elementTransform: (Int) -> Int32?,
167+
_ transformation: (Int) -> Int32?,
168168
file: String = #file, line: UInt = #line
169169
) {
170170
self.expected = expected
171171
self.sequence = sequence
172-
self.transform = elementTransform
172+
self.transform = transformation
173173
self.loc = SourceLoc(file, line, comment: "test data")
174174
}
175175
}
@@ -230,12 +230,12 @@ public struct MapTest {
230230
public init(
231231
_ expected: [Int32],
232232
_ sequence: [Int],
233-
_ elementTransform: (Int) -> Int32,
233+
_ transformation: (Int) -> Int32,
234234
file: String = #file, line: UInt = #line
235235
) {
236236
self.expected = expected
237237
self.sequence = sequence
238-
self.transform = elementTransform
238+
self.transform = transformation
239239
self.loc = SourceLoc(file, line, comment: "test data")
240240
}
241241
}

stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb

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

224224
public func map<T>(
225-
_ elementTransform: @noescape (Base.Iterator.Element) throws -> T
225+
_ transformation: @noescape (Base.Iterator.Element) throws -> T
226226
) rethrows -> [T] {
227227
Log.map[selfType] += 1
228-
return try base.map(elementTransform)
228+
return try base.map(transformation)
229229
}
230230

231231
public func `where`(

stdlib/public/core/Collection.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,13 +1262,13 @@ extension Collection {
12621262
/// let letterCounts = cast.map { $0.characters.count }
12631263
/// // 'letterCounts' == [6, 6, 3, 4]
12641264
///
1265-
/// - Parameter elementTransform: A mapping closure. `transform` accepts an
1265+
/// - Parameter transformation: A mapping closure. `transformation` accepts an
12661266
/// element of this sequence as its parameter and returns a transformed
12671267
/// value of the same or of a different type.
12681268
/// - Returns: An array containing the transformed elements of this
12691269
/// sequence.
12701270
public func map<T>(
1271-
_ elementTransform: @noescape (Iterator.Element) throws -> T
1271+
_ transformation: @noescape (Iterator.Element) throws -> T
12721272
) rethrows -> [T] {
12731273
let count: Int = numericCast(self.count)
12741274
if count == 0 {
@@ -1281,7 +1281,7 @@ extension Collection {
12811281
var i = self.startIndex
12821282

12831283
for _ in 0..<count {
1284-
result.append(try elementTransform(self[i]))
1284+
result.append(try transformation(self[i]))
12851285
formIndex(after: &i)
12861286
}
12871287

stdlib/public/core/ExistentialCollection.swift.gyb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ internal class _AnyRandomAccessCollectionBox<Element>
145145
internal var _underestimatedCount: Int { _abstract() }
146146

147147
internal func _map<T>(
148-
_ elementTransform: @noescape (Element) throws -> T
148+
_ transformation: @noescape (Element) throws -> T
149149
) rethrows -> [T] {
150150
_abstract()
151151
}
@@ -334,9 +334,9 @@ internal final class _${Kind}Box<S : ${Kind}> : _Any${Kind}Box<S.Iterator.Elemen
334334
return _base.underestimatedCount
335335
}
336336
internal override func _map<T>(
337-
_ elementTransform: @noescape (Element) throws -> T
337+
_ transformation: @noescape (Element) throws -> T
338338
) rethrows -> [T] {
339-
return try _base.map(elementTransform)
339+
return try _base.map(transformation)
340340
}
341341
internal override func _where(
342342
_ isIncluded: @noescape (Element) throws -> Bool
@@ -577,9 +577,9 @@ extension Any${Kind} {
577577
}
578578

579579
public func map<T>(
580-
_ elementTransform: @noescape (Element) throws -> T
580+
_ transformation: @noescape (Element) throws -> T
581581
) rethrows -> [T] {
582-
return try _box._map(elementTransform)
582+
return try _box._map(transformation)
583583
}
584584

585585
public func `where`(

stdlib/public/core/FlatMap.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,70 +11,70 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
extension LazySequenceProtocol {
14-
/// Returns the concatenated results of mapping `elementTransform`
14+
/// Returns the concatenated results of mapping `transformation`
1515
/// over `self`. Equivalent to
1616
///
17-
/// self.map(elementTransform).flatten()
17+
/// self.map(transformation).flatten()
1818
///
1919
/// - Complexity: O(1)
2020
public func flatMap<SegmentOfResult : Sequence>(
21-
_ elementTransform: (Elements.Iterator.Element) -> SegmentOfResult
21+
_ transformation: (Elements.Iterator.Element) -> SegmentOfResult
2222
) -> LazySequence<
2323
FlattenSequence<LazyMapSequence<Elements, SegmentOfResult>>> {
24-
return self.map(elementTransform).flatten()
24+
return self.map(transformation).flatten()
2525
}
2626

2727
/// Returns a `LazyMapSequence` containing the concatenated non-nil
28-
/// results of mapping `elementTransform` over this `Sequence`.
28+
/// results of mapping `transformation` over this `Sequence`.
2929
///
3030
/// Use this method to receive only nonoptional values when your
3131
/// transformation produces an optional value.
3232
///
33-
/// - Parameter elementTransform: A closure that accepts an element of this
33+
/// - Parameter transformation: A closure that accepts an element of this
3434
/// sequence as its argument and returns an optional value.
3535
public func flatMap<ElementOfResult>(
36-
_ elementTransform: (Elements.Iterator.Element) -> ElementOfResult?
36+
_ transformation: (Elements.Iterator.Element) -> ElementOfResult?
3737
) -> LazyMapSequence<
3838
LazyFilterSequence<
3939
LazyMapSequence<Elements, ElementOfResult?>>,
4040
ElementOfResult
4141
> {
42-
return self.map(elementTransform).where { $0 != nil }.map { $0! }
42+
return self.map(transformation).where { $0 != nil }.map { $0! }
4343
}
4444
}
4545

4646
extension LazyCollectionProtocol {
47-
/// Returns the concatenated results of mapping `elementTransform` over
47+
/// Returns the concatenated results of mapping `transformation` over
4848
/// `self`. Equivalent to
4949
///
50-
/// self.map(elementTransform).flatten()
50+
/// self.map(transformation).flatten()
5151
///
5252
/// - Complexity: O(1)
5353
public func flatMap<SegmentOfResult : Collection>(
54-
_ elementTransform: (Elements.Iterator.Element) -> SegmentOfResult
54+
_ transformation: (Elements.Iterator.Element) -> SegmentOfResult
5555
) -> LazyCollection<
5656
FlattenCollection<
5757
LazyMapCollection<Elements, SegmentOfResult>>
5858
> {
59-
return self.map(elementTransform).flatten()
59+
return self.map(transformation).flatten()
6060
}
6161

6262
/// Returns a `LazyMapCollection` containing the concatenated non-nil
63-
/// results of mapping elementTransform over this collection.
63+
/// results of mapping transformation over this collection.
6464
///
6565
/// Use this method to receive only nonoptional values when your
6666
/// transformation produces an optional value.
6767
///
68-
/// - Parameter elementTransform: A closure that accepts an element of this
68+
/// - Parameter transformation: A closure that accepts an element of this
6969
/// collection as its argument and returns an optional value.
7070
public func flatMap<ElementOfResult>(
71-
_ elementTransform: (Elements.Iterator.Element) -> ElementOfResult?
71+
_ transformation: (Elements.Iterator.Element) -> ElementOfResult?
7272
) -> LazyMapCollection<
7373
LazyFilterCollection<
7474
LazyMapCollection<Elements, ElementOfResult?>>,
7575
ElementOfResult
7676
> {
77-
return self.map(elementTransform).where { $0 != nil }.map { $0! }
77+
return self.map(transformation).where { $0 != nil }.map { $0! }
7878
}
7979
}
8080

@@ -83,36 +83,36 @@ extension LazyCollectionProtocol
8383
Self : BidirectionalCollection,
8484
Elements : BidirectionalCollection
8585
{
86-
/// Returns the concatenated results of mapping `elementTransform` over
86+
/// Returns the concatenated results of mapping `transformation` over
8787
/// `self`. Equivalent to
8888
///
89-
/// self.map(elementTransform).flatten()
89+
/// self.map(transformation).flatten()
9090
///
9191
/// - Complexity: O(1)
9292
public func flatMap<SegmentOfResult : Collection>(
93-
_ elementTransform: (Elements.Iterator.Element) -> SegmentOfResult
93+
_ transformation: (Elements.Iterator.Element) -> SegmentOfResult
9494
) -> LazyCollection<
9595
FlattenBidirectionalCollection<
9696
LazyMapBidirectionalCollection<Elements, SegmentOfResult>>>
9797
where SegmentOfResult : BidirectionalCollection {
98-
return self.map(elementTransform).flatten()
98+
return self.map(transformation).flatten()
9999
}
100100

101101
/// Returns a `LazyMapBidirectionalCollection` containing the concatenated non-nil
102-
/// results of mapping elementTransform over this collection.
102+
/// results of mapping transformation over this collection.
103103
///
104104
/// Use this method to receive only nonoptional values when your
105105
/// transformation produces an optional value.
106106
///
107-
/// - Parameter elementTransform: A closure that accepts an element of this
107+
/// - Parameter transformation: A closure that accepts an element of this
108108
/// collection as its argument and returns an optional value.
109109
public func flatMap<ElementOfResult>(
110-
_ elementTransform: (Elements.Iterator.Element) -> ElementOfResult?
110+
_ transformation: (Elements.Iterator.Element) -> ElementOfResult?
111111
) -> LazyMapBidirectionalCollection<
112112
LazyFilterBidirectionalCollection<
113113
LazyMapBidirectionalCollection<Elements, ElementOfResult?>>,
114114
ElementOfResult
115115
> {
116-
return self.map(elementTransform).where { $0 != nil }.map { $0! }
116+
return self.map(transformation).where { $0 != nil }.map { $0! }
117117
}
118118
}

stdlib/public/core/Map.swift.gyb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ public struct ${Self}<
204204
extension LazySequenceProtocol {
205205
/// Returns a `LazyMapSequence` over this `Sequence`. The elements of
206206
/// the result are computed lazily, each time they are read, by
207-
/// calling `elementTransform` function on a base element.
207+
/// calling `transformation` function on a base element.
208208
public func map<U>(
209-
_ elementTransform: (Elements.Iterator.Element) -> U
209+
_ transformation: (Elements.Iterator.Element) -> U
210210
) -> LazyMapSequence<Self.Elements, U> {
211-
return LazyMapSequence(_base: self.elements, transform: elementTransform)
211+
return LazyMapSequence(_base: self.elements, transform: transformation)
212212
}
213213
}
214214

@@ -221,13 +221,13 @@ extension LazyCollectionProtocol
221221
{
222222
/// Returns a `LazyMapCollection` over this `Collection`. The elements of
223223
/// the result are computed lazily, each time they are read, by
224-
/// calling `elementTransform` function on a base element.
224+
/// calling `transformation` function on a base element.
225225
public func map<U>(
226-
_ elementTransform: (Elements.Iterator.Element) -> U
226+
_ transformation: (Elements.Iterator.Element) -> U
227227
) -> LazyMap${collectionForTraversal(Traversal)}<Self.Elements, U> {
228228
return LazyMap${collectionForTraversal(Traversal)}(
229229
_base: self.elements,
230-
transform: elementTransform)
230+
transform: transformation)
231231
}
232232
}
233233

stdlib/public/core/Optional.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ public enum Optional<Wrapped> : NilLiteralConvertible {
157157
/// - Returns: The result of the given closure. If this instance is `nil`,
158158
/// returns `nil`.
159159
public func map<U>(
160-
_ elementTransform: @noescape (Wrapped) throws -> U
160+
_ transformation: @noescape (Wrapped) throws -> U
161161
) rethrows -> U? {
162162
switch self {
163163
case .some(let y):
164-
return .some(try elementTransform(y))
164+
return .some(try transformation(y))
165165
case .none:
166166
return .none
167167
}
@@ -185,10 +185,10 @@ public enum Optional<Wrapped> : NilLiteralConvertible {
185185
/// - Parameter f: A closure that takes the unwrapped value of the instance.
186186
/// - Returns: The result of the given closure. If this instance is `nil`,
187187
/// returns `nil`.
188-
public func flatMap<U>(_ elementTransform: @noescape (Wrapped) throws -> U?) rethrows -> U? {
188+
public func flatMap<U>(_ transformation: @noescape (Wrapped) throws -> U?) rethrows -> U? {
189189
switch self {
190190
case .some(let y):
191-
return try elementTransform(y)
191+
return try transformation(y)
192192
case .none:
193193
return .none
194194
}

stdlib/public/core/Sequence.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,13 @@ public protocol Sequence {
368368
/// let letterCounts = cast.map { $0.characters.count }
369369
/// // 'letterCounts' == [6, 6, 3, 4]
370370
///
371-
/// - Parameter transform: A mapping closure. `transform` accepts an
371+
/// - Parameter transform: A mapping closure. `transformation` accepts an
372372
/// element of this sequence as its parameter and returns a transformed
373373
/// value of the same or of a different type.
374374
/// - Returns: An array containing the transformed elements of this
375375
/// sequence.
376376
func map<T>(
377-
_ elementTransform: @noescape (Iterator.Element) throws -> T
377+
_ transformation: @noescape (Iterator.Element) throws -> T
378378
) rethrows -> [T]
379379

380380
/// Returns an array containing, in order, the elements of the sequence
@@ -709,13 +709,13 @@ extension Sequence {
709709
/// let letterCounts = cast.map { $0.characters.count }
710710
/// // 'letterCounts' == [6, 6, 3, 4]
711711
///
712-
/// - Parameter elementTransform: A mapping closure. `elementTransform` accepts an
712+
/// - Parameter transformation: A mapping closure. `transformation` accepts an
713713
/// element of this sequence as its parameter and returns a transformed
714714
/// value of the same or of a different type.
715715
/// - Returns: An array containing the transformed elements of this
716716
/// sequence.
717717
public func map<T>(
718-
_ elementTransform: @noescape (Iterator.Element) throws -> T
718+
_ transformation: @noescape (Iterator.Element) throws -> T
719719
) rethrows -> [T] {
720720
let initialCapacity = underestimatedCount
721721
var result = ContiguousArray<T>()
@@ -725,11 +725,11 @@ extension Sequence {
725725

726726
// Add elements up to the initial capacity without checking for regrowth.
727727
for _ in 0..<initialCapacity {
728-
result.append(try elementTransform(iterator.next()!))
728+
result.append(try transformation(iterator.next()!))
729729
}
730730
// Add remaining elements, if any.
731731
while let element = iterator.next() {
732-
result.append(try elementTransform(element))
732+
result.append(try transformation(element))
733733
}
734734
return Array(result)
735735
}

0 commit comments

Comments
 (0)