mirror of
https://github.com/vlang/v.git
synced 2025-09-16 07:52:32 +03:00
arrays: add arrays.chunk_while/2, where arrays.chunk_while([0,9,2,2,3,2],fn(x int,y int)bool{return x<=y})==[[0,9],[2,2,3],[2]]
This commit is contained in:
parent
8188f65590
commit
879cf1ed21
2 changed files with 47 additions and 0 deletions
|
@ -147,6 +147,22 @@ fn test_chunk() {
|
|||
assert chunk[int]([]int{}, 2) == [][]int{}
|
||||
}
|
||||
|
||||
fn test_chunk_while() {
|
||||
assert chunk_while([0, 9, 2, 2, 3, 2, 7, 5, 9, 5], fn (x int, y int) bool {
|
||||
return x == y
|
||||
}) == [[0], [9], [2, 2], [3], [2], [7], [5], [9], [5]]
|
||||
|
||||
assert chunk_while([0, 9, 2, 2, 3, 2, 7, 5, 9, 5], fn (x int, y int) bool {
|
||||
return x <= y
|
||||
}) == [[0, 9], [2, 2, 3], [2, 7], [5, 9], [5]]
|
||||
|
||||
assert chunk_while('aaaabbbcca'.runes(), fn (x rune, y rune) bool {
|
||||
return x == y
|
||||
}).map({
|
||||
it[0]: it.len
|
||||
}).str() == '[{`a`: 4}, {`b`: 3}, {`c`: 2}, {`a`: 1}]'
|
||||
}
|
||||
|
||||
fn test_window() {
|
||||
x := [1, 2, 3, 4, 5, 6]
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue