Skip to content

Commit 1dce37e

Browse files
committed
* Fix print(_:separator =) with print(_:separator:terminator)
* Add optional binding for using optional first, last property
1 parent e7c81c5 commit 1dce37e

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

stdlib/public/core/Arrays.swift.gyb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,11 @@ if True:
229229
/// array's first and last elements. If the array is empty, these properties
230230
/// are `nil`.
231231
///
232-
/// print(oddNumbers.first, oddNumbers.last, separator=", ")
232+
/// if let firstElement = oddNumbers.first, lastElement = oddNumbers.last {
233+
/// print(firstElement, lastElement, separator: ", ", terminator: "\n")
233234
/// // Prints "1, 15"
234235
///
235-
/// print(emptyDoubles.first, emptyDoubles.last, separator=", ")
236+
/// print(emptyDoubles.first, emptyDoubles.last, separator: ", ", terminator: "\n")
236237
/// // Prints "nil, nil"
237238
///
238239
/// You can access individual array elements through a subscript. The first
@@ -241,7 +242,7 @@ if True:
241242
/// the count of the array. Using a negative number or an index equal to or
242243
/// greater than `count` triggers a runtime error. For example:
243244
///
244-
/// print(oddNumbers[0], oddNumbers[3], separator=", ")
245+
/// print(oddNumbers[0], oddNumbers[3], separator: ", ", terminator: "\n")
245246
/// // Prints "1, 7"
246247
///
247248
/// print(emptyDoubles[0])
@@ -619,10 +620,10 @@ ${SubscriptDocComment}
619620
public subscript(index: Int) -> Element {
620621
get {
621622
// This call may be hoisted or eliminated by the optimizer. If
622-
// there is an inout violation, this value may be stale so needs to be
623+
// there is an inout violation, this value may be stale so needs to be
623624
// checked again below.
624625
let wasNativeTypeChecked = _hoistableIsNativeTypeChecked()
625-
626+
626627
// Make sure the index is in range and wasNativeTypeChecked is
627628
// still valid.
628629
let token = _checkSubscript(
@@ -634,7 +635,7 @@ ${SubscriptDocComment}
634635
}
635636
mutableAddressWithPinnedNativeOwner {
636637
_makeMutableAndUniqueOrPinned() // makes the array native, too
637-
_checkSubscript_native(index)
638+
_checkSubscript_native(index)
638639
return (_getElementAddress(index), Builtin.tryPin(_getOwner_native()))
639640
}
640641
}
@@ -750,7 +751,7 @@ ${SubscriptDocComment}
750751
// We are hiding the access to '_buffer.owner' behind
751752
// _getOwner() to help the compiler hoist uniqueness checks in
752753
// the case of class or Objective-C existential typed array
753-
// elements.
754+
// elements.
754755
return _getOwnerWithSemanticLabel_native()
755756
}
756757
#endif
@@ -990,12 +991,12 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
990991
/// func cacheImagesWithNames(names: [String]) {
991992
/// // custom image loading and caching
992993
/// }
993-
///
994+
///
994995
/// let namedHues: [String: Int] = ["Vermillion": 18, "Magenta": 302,
995996
/// "Gold": 50, "Cerise": 320]
996997
/// let colorNames = Array(namedHues.keys)
997998
/// cacheImagesWithNames(colorNames)
998-
///
999+
///
9991000
/// print(colorNames)
10001001
/// // Prints "["Gold", "Cerise", "Magenta", "Vermillion"]"
10011002
///
@@ -1082,15 +1083,15 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
10821083
internal static func _adoptStorage(
10831084
_ storage: AnyObject, count: Int
10841085
) -> (Array, UnsafeMutablePointer<Element>) {
1085-
1086+
10861087
_sanityCheck(
10871088
storage is _ContiguousArrayStorage<Element>, "Invalid array storage type")
1088-
1089+
10891090
let innerBuffer = _ContiguousArrayBuffer<Element>(
10901091
count: count,
10911092
storage: unsafeDowncast(
10921093
storage, to: _ContiguousArrayStorage<Element>.self))
1093-
1094+
10941095
return (
10951096
Array(_Buffer(innerBuffer, shiftedToStartIndex: 0)),
10961097
innerBuffer.firstElementAddress)

0 commit comments

Comments
 (0)