Closed
Description
The documentation of chunked(by:)
states that the predicate is evaluated on consecutive elements. Experience and a naive look at the source are suggesting it is evaluated using the first element of the chunk instead of the previous one.
Steps to Reproduce
Let a: [Int] = [1,2,3,4,6,7,8,9]
("5" is missing). We want to chunk a
such as two consecutive elements are consecutive numbers (their difference is exactly 1).
Expected behavior
[1,2,3,4,6,7,8,9].chunked(by: { $1 - $0 == 1 }) == [[1, 2, 3, 4], [6, 7, 8, 9]]
Actual behavior
[1,2,3,4,6,7,8,9].chunked(by: { $1 - $0 == 1 }) == [[1, 2], [3, 4], [6, 7], [8, 9]]
Am I understanding the documentation incorrectly, or is there an inconsistency between the documentation and the expected behavior?
Metadata
Metadata
Assignees
Labels
No labels