Skip to content

Commit 3360204

Browse files
committed
arrays: fix v doc -unsafe-run-examples -f none vlib/arrays/ too
1 parent 9771491 commit 3360204

3 files changed

Lines changed: 9 additions & 10 deletions

File tree

‎vlib/arrays/arrays.v‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub fn group[T](arrs ...[]T) [][]T {
154154
}
155155

156156
// chunk array into a single array of arrays where each element is the next `size` elements of the original.
157-
// Example: arrays.chunk([1, 2, 3, 4, 5, 6, 7, 8, 9], 2)) // => [[1, 2], [3, 4], [5, 6], [7, 8], [9]]
157+
// Example: arrays.chunk([1, 2, 3, 4, 5, 6, 7, 8, 9], 2) // => [[1, 2], [3, 4], [5, 6], [7, 8], [9]]
158158
pub fn chunk[T](array []T, size int) [][]T {
159159
// allocate chunk array
160160
mut chunks := [][]T{cap: array.len / size + if array.len % size == 0 { 0 } else { 1 }}
@@ -425,11 +425,10 @@ pub fn group_by[K, V](array []V, grouping_op fn (val V) K) map[K][]V {
425425
}
426426

427427
// concatenate an array with an arbitrary number of additional values.
428-
//
429-
// NOTE: if you have two arrays, you should simply use the `<<` operator directly
430-
// Example: arrays.concat([1, 2, 3], 4, 5, 6) == [1, 2, 3, 4, 5, 6] // => true
431-
// Example: arrays.concat([1, 2, 3], ...[4, 5, 6]) == [1, 2, 3, 4, 5, 6] // => true
432-
// Example: arr << [4, 5, 6] // does what you need if arr is mutable
428+
// NOTE: if you have two arrays, you should simply use the `<<` operator directly.
429+
// Example: assert arrays.concat([1, 2, 3], 4, 5, 6) == [1, 2, 3, 4, 5, 6]
430+
// Example: assert arrays.concat([1, 2, 3], ...[4, 5, 6]) == [1, 2, 3, 4, 5, 6]
431+
// Example: mut arr := arrays.concat([1, 2, 3], 4); arr << [10,20]; assert arr == [1,2,3,4,10,20] // note: arr is mutable
433432
pub fn concat[T](a []T, b ...T) []T {
434433
mut m := []T{cap: a.len + b.len}
435434

‎vlib/arrays/index_of.v‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module arrays
22

33
// index_of_first returns the index of the first element of `array`, for which the predicate fn returns true.
44
// If predicate does not return true for any of the elements, then index_of_first will return -1.
5-
// Example: arrays.index_of_first([4,5,0,7,0,9], fn(idx int, x int) bool { return x == 0 }) == 2
5+
// Example: assert arrays.index_of_first([4,5,0,7,0,9], fn(idx int, x int) bool { return x == 0 }) == 2
66
pub fn index_of_first[T](array []T, predicate fn (idx int, elem T) bool) int {
77
for i, e in array {
88
if predicate(i, e) {
@@ -14,7 +14,7 @@ pub fn index_of_first[T](array []T, predicate fn (idx int, elem T) bool) int {
1414

1515
// index_of_last returns the index of the last element of `array`, for which the predicate fn returns true.
1616
// If predicate does not return true for any of the elements, then index_of_last will return -1.
17-
// Example: arrays.index_of_last([4,5,0,7,0,9], fn(idx int, x int) bool { return x == 0 }) == 4
17+
// Example: assert arrays.index_of_last([4,5,0,7,0,9], fn(idx int, x int) bool { return x == 0 }) == 4
1818
pub fn index_of_last[T](array []T, predicate fn (idx int, elem T) bool) int {
1919
for i := array.len - 1; i >= 0; i-- {
2020
e := array[i]

‎vlib/arrays/map_of.v‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module arrays
22

33
// map_of_indexes returns a map, where each key is an unique value in `array`.
44
// Each value in that map for that key, is an array, containing the indexes in `array`, where that value has been found.
5-
// Example: arrays.map_of_indexes([1,2,3,4,4,2,1,4,4,999]) == {1: [0, 6], 2: [1, 5], 3: [2], 4: [3, 4, 7, 8], 999: [9]}
5+
// Example: assert arrays.map_of_indexes([1,2,3,4,4,2,1,4,4,999]) == {1: [0, 6], 2: [1, 5], 3: [2], 4: [3, 4, 7, 8], 999: [9]}
66
pub fn map_of_indexes[T](array []T) map[T][]int {
77
mut result := map[T][]int{}
88
for i, e in array {
@@ -18,7 +18,7 @@ pub fn map_of_indexes[T](array []T) map[T][]int {
1818
// map_of_counts returns a map, where each key is an unique value in `array`.
1919
// Each value in that map for that key, is how many times that value occurs in `array`.
2020
// It can be useful for building histograms of discrete measurements.
21-
// Example: arrays.map_of_counts([1,2,3,4,4,2,1,4,4]) == {1: 2, 2: 2, 3: 1, 4: 4}
21+
// Example: assert arrays.map_of_counts([1,2,3,4,4,2,1,4,4]) == {1: 2, 2: 2, 3: 1, 4: 4}
2222
pub fn map_of_counts[T](array []T) map[T]int {
2323
mut result := map[T]int{}
2424
for e in array {

0 commit comments

Comments
 (0)