Skip to content

Commit 534881c

Browse files
committed
Update documentation to reflect API split
1 parent b0f3020 commit 534881c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Guides/AdjacentPairs.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@ let pairs = numbers.adjacentPairs()
1515

1616
## Detailed Design
1717

18-
The `adjacentPairs()` method is declared as a `Sequence` extension returning `AdjacentPairs`.
18+
The `adjacentPairs()` method is declared as a `Sequence` extension returning `AdjacentPairsSequence` and as a `Collection` extension return `AdjacentPairsCollection`.
1919

2020
```swift
2121
extension Sequence {
22-
public func adjacentPairs() -> AdjacentPairs<Self>
22+
public func adjacentPairs() -> AdjacentPairsSequence<Self>
2323
}
2424
```
2525

26-
The resulting `AdjacentPairs` type is a sequence, with conditional conformance to `Collection`, `BidirectionalCollection`, and `RandomAccessCollection` when the underlying sequence conforms.
26+
```swift
27+
extension Collection {
28+
public func adjacentPairs() -> AdjacentPairsCollection<Self>
29+
}
30+
```
2731

28-
The spelling `zip(s, s.dropFirst())` for a sequence `s` is an equivalent operation on collection types; however, this implementation is undefined behavior on single-pass sequences, and `Zip2Sequence` does not conditionally conform to the `Collection` family of protocols.
32+
The `AdjacentPairsSequence` type is a sequence, and the `AdjacentPairsCollection` type is a collection with conditional conformance to `BidirectionalCollection` and `RandomAccessCollection` when the underlying sequence conforms.
2933

3034
### Complexity
3135

@@ -44,3 +48,5 @@ This function is often written as a `zip` of a sequence together with itself, mi
4448
**Haskell:** This operation is spelled ``s `zip` tail s``.
4549

4650
**Python:** Python users may write `zip(s, s[1:])` for a list with at least one element. For natural language processing, the `nltk` package offers a `bigrams` function akin to this method.
51+
52+
Note that in Swift, `zip(s, s.dropFirst())` is undefined behavior on single-pass sequences.

0 commit comments

Comments
 (0)