mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
checker, cgen: implement method map() for fixed arrays (#22644)
This commit is contained in:
parent
4e9f7c21aa
commit
5ad0186895
4 changed files with 111 additions and 20 deletions
27
vlib/builtin/fixed_array_map_test.v
Normal file
27
vlib/builtin/fixed_array_map_test.v
Normal file
|
@ -0,0 +1,27 @@
|
|||
fn test_fixed_array_map() {
|
||||
a := [1, 2, 3]!
|
||||
|
||||
b1 := a.map(it * 2)
|
||||
println(b1)
|
||||
assert b1 == [2, 4, 6]!
|
||||
|
||||
b11 := a.map(|x| x * 2)
|
||||
println(b11)
|
||||
assert b11 == [2, 4, 6]!
|
||||
|
||||
b2 := a.map('${it}')
|
||||
println(b2)
|
||||
assert b2 == ['1', '2', '3']!
|
||||
|
||||
b22 := a.map(|x| '${x}')
|
||||
println(b22)
|
||||
assert b22 == ['1', '2', '3']!
|
||||
|
||||
b3 := a.map(it + 2)
|
||||
println(b3)
|
||||
assert b3 == [3, 4, 5]!
|
||||
|
||||
b33 := a.map(|x| x + 2)
|
||||
println(b33)
|
||||
assert b33 == [3, 4, 5]!
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue