Skip to content

Commit

Permalink
Fix chunks(countOf: 1) (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
FranzBusch authored Sep 19, 2023
1 parent 4a1fb99 commit 281e27c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/AsyncAlgorithms/AsyncChunksOfCountSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public struct AsyncChunksOfCountSequence<Base: AsyncSequence, Collected: RangeRe
return nil
}

if count == 1 {
return Collected(CollectionOfOne(first))
}

var result: Collected = .init()
result.append(first)

Expand Down
8 changes: 8 additions & 0 deletions Tests/AsyncAlgorithmsTests/TestChunk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ func concatCharacters(_ array: [String]) -> String {
}

final class TestChunk: XCTestCase {
func test_count_one() {
validate {
"ABCDE|"
$0.inputs[0].chunks(ofCount: 1).map(concatCharacters)
"ABCDE|"
}
}

func test_signal_equalChunks() {
validate {
"ABC- DEF- GHI- |"
Expand Down

0 comments on commit 281e27c

Please sign in to comment.