Skip to content

Commit 281e27c

Browse files
authored
Fix chunks(countOf: 1) (#293)
1 parent 4a1fb99 commit 281e27c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Sources/AsyncAlgorithms/AsyncChunksOfCountSequence.swift

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public struct AsyncChunksOfCountSequence<Base: AsyncSequence, Collected: RangeRe
4949
return nil
5050
}
5151

52+
if count == 1 {
53+
return Collected(CollectionOfOne(first))
54+
}
55+
5256
var result: Collected = .init()
5357
result.append(first)
5458

Tests/AsyncAlgorithmsTests/TestChunk.swift

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ func concatCharacters(_ array: [String]) -> String {
2424
}
2525

2626
final class TestChunk: XCTestCase {
27+
func test_count_one() {
28+
validate {
29+
"ABCDE|"
30+
$0.inputs[0].chunks(ofCount: 1).map(concatCharacters)
31+
"ABCDE|"
32+
}
33+
}
34+
2735
func test_signal_equalChunks() {
2836
validate {
2937
"ABC- DEF- GHI- |"

0 commit comments

Comments
 (0)