Skip to content

Commit 8f664a1

Browse files
committed
Documentation improvements
1 parent 622a82b commit 8f664a1

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

Guides/AdjacentPairs.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
Lazily iterates over tuples of adjacent elements.
77

8-
This operation is available for any sequence by calling the `adjacentPairs()`
9-
method.
10-
118
```swift
129
let numbers = (1...5)
1310
let pairs = numbers.adjacentPairs()

Guides/Grouped.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55

66
Groups up elements of a sequence into a new Dictionary, whose values are Arrays of grouped elements, each keyed by the result of the given closure.
77

8-
This operation is available for any sequence by calling the `grouped(by:)`
9-
method.
10-
118
```swift
129
let fruits = ["Apricot", "Banana", "Apple", "Cherry", "Avocado", "Coconut"]
1310
let fruitsByLetter = fruits.grouped(by: { $0.first! })
1411
// Results in:
15-
[
16-
"B": ["Banana"],
17-
"A": ["Apricot", "Apple", "Avocado"],
18-
"C": ["Cherry", "Coconut"],
19-
]
12+
// [
13+
// "B": ["Banana"],
14+
// "A": ["Apricot", "Apple", "Avocado"],
15+
// "C": ["Cherry", "Coconut"],
16+
// ]
2017
```
2118

2219
If you wish to achieve a similar effect but for single values (instead of Arrays of grouped values), see [`keyed(by:)`](Keyed.md).

Guides/Keyed.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# Indexed
22

3-
[[Source](https://github.com/apple/swift-algorithms/blob/main/Sources/Algorithms/Indexed.swift) |
4-
[Tests](https://github.com/apple/swift-algorithms/blob/main/Tests/SwiftAlgorithmsTests/IndexedTests.swift)]
3+
[[Source](https://github.com/apple/swift-algorithms/blob/main/Sources/Algorithms/Keyed.swift) |
4+
[Tests](https://github.com/apple/swift-algorithms/blob/main/Tests/SwiftAlgorithmsTests/KeyedTests.swift)]
55

66
Stores the elements of a sequence as the values of a Dictionary, keyed by the result of the given closure.
77

88
```swift
99
let fruits = ["Apple", "Banana", "Cherry"]
1010
let fruitByLetter = fruits.keyed(by: { $0.first! })
1111
// Results in:
12-
[
13-
"A": "Apple",
14-
"B": "Banana",
15-
"C": "Cherry",
16-
]
12+
// [
13+
// "A": "Apple",
14+
// "B": "Banana",
15+
// "C": "Cherry",
16+
// ]
1717
```
1818

1919
Duplicate keys will trigger a runtime error by default. To handle this, you can provide a closure which specifies which value to keep:
@@ -25,11 +25,11 @@ let fruitsByLetter = fruits.keyed(
2525
uniquingKeysWith: { key, old, new in new } // Always pick the latest fruit
2626
)
2727
// Results in:
28-
[
29-
"A": "Avocado",
30-
"B": "Blackberry"],
31-
"C": ["Coconut"],
32-
]
28+
// [
29+
// "A": "Avocado",
30+
// "B": "Blackberry"],
31+
// "C": "Coconut",
32+
// ]
3333
```
3434

3535
## Detailed Design

0 commit comments

Comments
 (0)