mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-24 04:17:48 +00:00
* Finish sub-page documentation updates Some of these pages could use introductions, but the current state is ready for publication. * Add SPI yaml file for building docs
43 lines
626 B
Markdown
43 lines
626 B
Markdown
# Extending
|
|
|
|
Chain two collections end-to-end,
|
|
or repeat a collection forever or a specific number of times.
|
|
|
|
## Overview
|
|
|
|
_Chaining_ two collections
|
|
|
|
```swift
|
|
let letters = chain("abcd", "EFGH")
|
|
// String(letters) == "abcdEFGH"
|
|
|
|
for (num, letter) in zip((1...3).cycled(), letters) {
|
|
print(num, letter)
|
|
}
|
|
// 1 a
|
|
// 2 b
|
|
// 3 c
|
|
// 1 d
|
|
// 2 E
|
|
// 3 F
|
|
// 1 G
|
|
// 2 H
|
|
```
|
|
|
|
## Topics
|
|
|
|
### Chaining Two Collections
|
|
|
|
- ``chain(_:_:)``
|
|
|
|
### Cycling a Collection
|
|
|
|
- ``Swift/Collection/cycled()``
|
|
- ``Swift/Collection/cycled(times:)``
|
|
|
|
### Supporting Types
|
|
|
|
- ``Chain2Sequence``
|
|
- ``CycledSequence``
|
|
- ``CycledTimesCollection``
|