Skip to content

Commit 481bcab

Browse files
author
Max Moiseev
committedFeb 22, 2016
[stdlib] API naming guidelines applied to split and join
- `separator` label for first argument of `split` - `join` and related types are renamed to `joined`
1 parent fcad164 commit 481bcab

File tree

12 files changed

+36
-36
lines changed

12 files changed

+36
-36
lines changed
 

‎benchmark/single-source/Join.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ public func run_Join(N: Int) {
1919
for x in 0..<1000 * N {
2020
array.append(String(x))
2121
}
22-
_ = array.join(separator: "")
23-
_ = array.join(separator: " ")
22+
_ = array.joined(separator: "")
23+
_ = array.joined(separator: " ")
2424
}

‎stdlib/private/StdlibCollectionUnittest/CheckSequenceType.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,7 @@ self.test("\(testNamePrefix).split/separator/semantics") {
16991699
)
17001700
let separator = wrapValueIntoEquatable(MinimalEquatableValue(test.separator))
17011701
let result = s.split(
1702-
by: separator,
1702+
separator: separator,
17031703
maxSplits: test.maxSplits,
17041704
omittingEmptySubsequences: test.omittingEmptySubsequences)
17051705
expectEqualSequence(
@@ -1726,7 +1726,7 @@ self.test("\(testNamePrefix).split/semantics/separator/negativeMaxSplit") {
17261726
let s = makeWrappedSequenceWithEquatableElement([MinimalEquatableValue(1)])
17271727
let separator = wrapValueIntoEquatable(MinimalEquatableValue(1))
17281728
expectCrashLater()
1729-
_ = s.split(by: separator, maxSplits: -1, omittingEmptySubsequences: false)
1729+
_ = s.split(separator: separator, maxSplits: -1, omittingEmptySubsequences: false)
17301730
}
17311731

17321732
//===----------------------------------------------------------------------===//

‎stdlib/private/SwiftPrivate/SwiftPrivate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public func asHex<
2424
where
2525
S.Iterator.Element : Integer
2626
>(x: S) -> String {
27-
return "[ " + x.lazy.map { asHex($0) }.join(separator: ", ") + " ]"
27+
return "[ " + x.lazy.map { asHex($0) }.joined(separator: ", ") + " ]"
2828
}
2929

3030
/// Compute the prefix sum of `seq`.

‎stdlib/public/core/Collection.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ extension Collection where Iterator.Element : Equatable {
489489
/// - Precondition: `maxSplits >= 0`
490490
@warn_unused_result
491491
public func split(
492-
by separator: Iterator.Element,
492+
separator separator: Iterator.Element,
493493
maxSplits: Int = Int.max,
494494
omittingEmptySubsequences: Bool = true
495495
) -> [SubSequence] {
@@ -764,9 +764,9 @@ extension Collection {
764764
}
765765

766766
extension Collection where Iterator.Element : Equatable {
767-
@available(*, unavailable, message="Please use split(_:maxSplits:omittingEmptySubsequences:) instead")
767+
@available(*, unavailable, message="Please use split(separator:maxSplits:omittingEmptySubsequences:) instead")
768768
public func split(
769-
by separator: Iterator.Element,
769+
separator: Iterator.Element,
770770
maxSplit: Int = Int.max,
771771
allowEmptySlices: Bool = false
772772
) -> [SubSequence] {

‎stdlib/public/core/Join.swift

+13-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal enum _JoinIteratorState {
1919

2020
/// An iterator that presents the elements of the sequences traversed
2121
/// by `Base`, concatenated using a given separator.
22-
public struct JoinIterator<
22+
public struct JoinedIterator<
2323
Base : IteratorProtocol where Base.Element : Sequence
2424
> : IteratorProtocol {
2525

@@ -90,7 +90,7 @@ public struct JoinIterator<
9090

9191
/// A sequence that presents the elements of the `Base` sequences
9292
/// concatenated using a given separator.
93-
public struct JoinSequence<
93+
public struct JoinedSequence<
9494
Base : Sequence where Base.Iterator.Element : Sequence
9595
> : Sequence {
9696

@@ -110,8 +110,8 @@ public struct JoinSequence<
110110
/// Return an iterator over the elements of this sequence.
111111
///
112112
/// - Complexity: O(1).
113-
public func iterator() -> JoinIterator<Base.Iterator> {
114-
return JoinIterator(
113+
public func iterator() -> JoinedIterator<Base.Iterator> {
114+
return JoinedIterator(
115115
base: _base.iterator(),
116116
separator: _separator)
117117
}
@@ -163,37 +163,37 @@ extension Sequence where Iterator.Element : Sequence {
163163
/// `separator` between the elements of the sequence `self`.
164164
///
165165
/// For example,
166-
/// `[[1, 2, 3], [4, 5, 6], [7, 8, 9]].join(separator: [-1, -2])`
166+
/// `[[1, 2, 3], [4, 5, 6], [7, 8, 9]].joined(separator: [-1, -2])`
167167
/// yields `[1, 2, 3, -1, -2, 4, 5, 6, -1, -2, 7, 8, 9]`.
168168
@warn_unused_result
169-
public func join<
169+
public func joined<
170170
Separator : Sequence
171171
where
172172
Separator.Iterator.Element == Iterator.Element.Iterator.Element
173-
>(separator separator: Separator) -> JoinSequence<Self> {
174-
return JoinSequence(base: self, separator: separator)
173+
>(separator separator: Separator) -> JoinedSequence<Self> {
174+
return JoinedSequence(base: self, separator: separator)
175175
}
176176
}
177177

178-
@available(*, unavailable, renamed="JoinIterator")
178+
@available(*, unavailable, renamed="JoinedIterator")
179179
public struct JoinGenerator<
180180
Base : IteratorProtocol where Base.Element : Sequence
181181
> {}
182182

183-
extension JoinSequence {
183+
extension JoinedSequence {
184184
@available(*, unavailable, renamed="iterator")
185-
public func generate() -> JoinIterator<Base.Iterator> {
185+
public func generate() -> JoinedIterator<Base.Iterator> {
186186
fatalError("unavailable function can't be called")
187187
}
188188
}
189189

190190
extension Sequence where Iterator.Element : Sequence {
191-
@available(*, unavailable, renamed="join")
191+
@available(*, unavailable, renamed="joined")
192192
public func joinWithSeparator<
193193
Separator : Sequence
194194
where
195195
Separator.Iterator.Element == Iterator.Element.Iterator.Element
196-
>(separator: Separator) -> JoinSequence<Self> {
196+
>(separator: Separator) -> JoinedSequence<Self> {
197197
fatalError("unavailable function can't be called")
198198
}
199199
}

‎stdlib/public/core/Sequence.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ extension Sequence where Iterator.Element : Equatable {
519519
/// - Precondition: `maxSplits >= 0`
520520
@warn_unused_result
521521
public func split(
522-
by separator: Iterator.Element,
522+
separator separator: Iterator.Element,
523523
maxSplits: Int = Int.max,
524524
omittingEmptySubsequences: Bool = true
525525
) -> [AnySequence<Iterator.Element>] {
@@ -671,9 +671,9 @@ extension Sequence {
671671
}
672672

673673
extension Sequence where Iterator.Element : Equatable {
674-
@available(*, unavailable, message="call 'split(_:omittingEmptySubsequences:isSeparator:)' and invert the 'allowEmptySlices' argument")
674+
@available(*, unavailable, message="call 'split(separator:omittingEmptySubsequences:isSeparator:)' and invert the 'allowEmptySlices' argument")
675675
public func split(
676-
by separator: Iterator.Element,
676+
separator: Iterator.Element,
677677
maxSplit: Int = Int.max,
678678
allowEmptySlices: Bool = false
679679
) -> [AnySequence<Iterator.Element>] {

‎stdlib/public/core/String.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,9 @@ extension Sequence where Iterator.Element == String {
610610
/// Interpose the `separator` between elements of `self`, then concatenate
611611
/// the result. For example:
612612
///
613-
/// ["foo", "bar", "baz"].join(separator: "-|-") // "foo-|-bar-|-baz"
613+
/// ["foo", "bar", "baz"].joined(separator: "-|-") // "foo-|-bar-|-baz"
614614
@warn_unused_result
615-
public func join(separator separator: String) -> String {
615+
public func joined(separator separator: String) -> String {
616616
var result = ""
617617

618618
// FIXME(performance): this code assumes UTF-16 in-memory representation.

‎test/1_stdlib/Mirror.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extension Mirror {
3737
return "[" +
3838
children.lazy
3939
.map { "\($0.0 ?? nil_): \(String(reflecting: $0.1))" }
40-
.join(separator: ", ")
40+
.joined(separator: ", ")
4141
+ "]"
4242
}
4343
}

‎test/SILOptimizer/devirt_type_subst_bug.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
// from ApplyInst to match what GenericSignature expects.
1717

1818
func asHex(a: [UInt8]) -> String {
19-
return a.map { "0x" + String($0, radix: 16) }.join(separator: "")
19+
return a.map { "0x" + String($0, radix: 16) }.joined(separator: "")
2020
}

‎test/expr/expressions.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,8 @@ func invalidDictionaryLiteral() {
674674

675675

676676
// FIXME: The issue here is a type compatibility problem, there is no ambiguity.
677-
[4].join(separator: [1]) // expected-error {{type of expression is ambiguous without more context}}
678-
[4].join(separator: [[[1]]]) // expected-error {{type of expression is ambiguous without more context}}
677+
[4].joined(separator: [1]) // expected-error {{type of expression is ambiguous without more context}}
678+
[4].joined(separator: [[[1]]]) // expected-error {{type of expression is ambiguous without more context}}
679679

680680
//===----------------------------------------------------------------------===//
681681
// nil/metatype comparisons

‎validation-test/compiler_crashers_fixed/00039-string-join.script.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
// Test case submitted to project by https://github.com/tmu (Teemu Kurppa)
44
// rdar://18174611
55

6-
["ab", "cd"].join(separator: "")
6+
["ab", "cd"].joined(separator: "")
77

‎validation-test/stdlib/Join.swift.gyb

+5-5
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ JoinTestSuite.test("${Base}.join()") {
282282
${Base}(${label} $0)
283283
})
284284
let separator = ${Base}(${label} test.separator)
285-
let r = Array(elements.join(separator: separator))
285+
let r = Array(elements.joined(separator: separator))
286286
checkSequence(test.expected, r)
287287
}
288288
}
@@ -293,18 +293,18 @@ JoinTestSuite.test("${Base}.join()/_copyToNativeArrayBuffer()") {
293293
${Base}(${label} $0)
294294
})
295295
let separator = ${Base}(${label} test.separator)
296-
let r = Array(elements.join(separator: separator))
296+
let r = Array(elements.joined(separator: separator))
297297
checkSequence(test.expected, r)
298298
}
299299
}
300300

301301
% end
302302

303303
func join(separator: String, _ elements: [String]) -> String {
304-
return elements.join(separator: separator)
304+
return elements.joined(separator: separator)
305305
}
306306

307-
JoinTestSuite.test("String.join(separator:)") {
307+
JoinTestSuite.test("String.joined(separator:)") {
308308
//
309309
// Test the free function.
310310
//
@@ -341,7 +341,7 @@ JoinTestSuite.test("String.join(separator:)") {
341341
// Test forwarding instance function.
342342
//
343343

344-
expectEqual("abxycdxyef", ["ab", "cd", "ef"].join(separator: "xy"))
344+
expectEqual("abxycdxyef", ["ab", "cd", "ef"].joined(separator: "xy"))
345345
}
346346

347347
runAllTests()

0 commit comments

Comments
 (0)
Please sign in to comment.