Skip to content

Commit 54cc59d

Browse files
authored
arrays: minor comments corrections (#18404)
1 parent e277862 commit 54cc59d

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

vlib/arrays/arrays.v

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module arrays
1010
// - flatten - reduce dimensionality of array by one. e.g. arrays.flatten([[1,2],[3,4],[5,6]]) => [1,2,3,4,5,6]
1111

1212
// min returns the minimum value in the array
13-
// Example: arrays.min([1,2,3,0,9]) // => 0
13+
// Example: arrays.min([1, 2, 3, 0, 9])! // => 0
1414
pub fn min[T](array []T) !T {
1515
if array.len == 0 {
1616
return error('.min called on an empty array')
@@ -25,7 +25,7 @@ pub fn min[T](array []T) !T {
2525
}
2626

2727
// max returns the maximum value in the array
28-
// Example: arrays.max([1,2,3,0,9]) // => 9
28+
// Example: arrays.max([1, 2, 3, 0, 9])! // => 9
2929
pub fn max[T](array []T) !T {
3030
if array.len == 0 {
3131
return error('.max called on an empty array')
@@ -40,7 +40,7 @@ pub fn max[T](array []T) !T {
4040
}
4141

4242
// idx_min returns the index of the minimum value in the array
43-
// Example: arrays.idx_min([1,2,3,0,9]) // => 3
43+
// Example: arrays.idx_min([1, 2, 3, 0, 9])! // => 3
4444
pub fn idx_min[T](array []T) !int {
4545
if array.len == 0 {
4646
return error('.idx_min called on an empty array')
@@ -57,7 +57,7 @@ pub fn idx_min[T](array []T) !int {
5757
}
5858

5959
// idx_max returns the index of the maximum value in the array
60-
// Example: arrays.idx_max([1,2,3,0,9]) // => 4
60+
// Example: arrays.idx_max([1, 2, 3, 0, 9])! // => 4
6161
pub fn idx_max[T](array []T) !int {
6262
if array.len == 0 {
6363
return error('.idx_max called on an empty array')
@@ -74,7 +74,7 @@ pub fn idx_max[T](array []T) !int {
7474
}
7575

7676
// merge two sorted arrays (ascending) and maintain sorted order
77-
// Example: arrays.merge([1,3,5,7], [2,4,6,8]) // => [1,2,3,4,5,6,7,8]
77+
// Example: arrays.merge([1, 3, 5, 7], [2, 4, 6, 8]) // => [1, 2, 3, 4, 5, 6, 7, 8]
7878
[direct_array_access]
7979
pub fn merge[T](a []T, b []T) []T {
8080
mut m := []T{len: a.len + b.len}
@@ -113,7 +113,7 @@ pub fn merge[T](a []T, b []T) []T {
113113
// To fully interleave two arrays, follow this function with a call to `flatten`.
114114
//
115115
// NOTE: An error will be generated if the type annotation is omitted.
116-
// Example: arrays.group<int>([1,2,3],[4,5,6]) // => [[1, 4], [2, 5], [3, 6]]
116+
// Example: arrays.group[int]([1, 2, 3], [4, 5, 6]) // => [[1, 4], [2, 5], [3, 6]]
117117
pub fn group[T](arrays ...[]T) [][]T {
118118
mut length := if arrays.len > 0 { arrays[0].len } else { 0 }
119119
// calculate length of output by finding shortest input array
@@ -199,7 +199,7 @@ pub fn window[T](array []T, attr WindowAttribute) [][]T {
199199
// NOTICE: currently V has bug that cannot make sum function takes custom struct with + operator overloaded
200200
// which means you can only pass array of numbers for now.
201201
// TODO: Fix generic operator overloading detection issue.
202-
// Example: arrays.sum<int>([1, 2, 3, 4, 5])? // => 15
202+
// Example: arrays.sum[int]([1, 2, 3, 4, 5])! // => 15
203203
pub fn sum[T](array []T) !T {
204204
if array.len == 0 {
205205
return error('Cannot sum up array of nothing.')
@@ -283,7 +283,7 @@ pub fn filter_indexed[T](array []T, predicate fn (idx int, elem T) bool) []T {
283283
// ```v
284284
// // Sum the length of each string in an array
285285
// a := ['Hi', 'all']
286-
// r := arrays.fold<string, int>(a, 0,
286+
// r := arrays.fold[string, int](a, 0,
287287
// fn (r int, t string) int { return r + t.len })
288288
// assert r == 5
289289
// ```
@@ -370,7 +370,7 @@ pub fn map_indexed[T, R](array []T, transform fn (idx int, elem T) R) []R {
370370
}
371371

372372
// group_by groups together elements, for which the `grouping_op` callback produced the same result.
373-
// Example: arrays.group_by<int, string>(['H', 'el', 'lo'], fn (v string) int { return v.len }) // => {1: ['H'], 2: ['el', 'lo']}
373+
// Example: arrays.group_by[int, string](['H', 'el', 'lo'], fn (v string) int { return v.len }) // => {1: ['H'], 2: ['el', 'lo']}
374374
pub fn group_by[K, V](array []V, grouping_op fn (val V) K) map[K][]V {
375375
mut result := map[K][]V{}
376376

@@ -404,7 +404,7 @@ pub fn concat[T](a []T, b ...T) []T {
404404
}
405405

406406
// returns the smallest element >= val, requires `array` to be sorted
407-
// Example: arrays.lower_bound([2, 4, 6, 8], 3)? // => 4
407+
// Example: arrays.lower_bound([2, 4, 6, 8], 3)! // => 4
408408
pub fn lower_bound[T](array []T, val T) !T {
409409
if array.len == 0 {
410410
return error('.lower_bound called on an empty array')
@@ -452,7 +452,7 @@ pub fn upper_bound[T](array []T, val T) !T {
452452
// binary search, requires `array` to be sorted, returns index of found item or error.
453453
// Binary searches on sorted lists can be faster than other array searches because at maximum
454454
// the algorithm only has to traverse log N elements
455-
// Example: arrays.binary_search([1, 2, 3, 4], 4)? // => 3
455+
// Example: arrays.binary_search([1, 2, 3, 4], 4)! // => 3
456456
pub fn binary_search[T](array []T, target T) !int {
457457
mut left := 0
458458
mut right := array.len - 1

0 commit comments

Comments
 (0)