V: Merging arrays errors out

Created on 16 Apr 2019  路  4Comments  路  Source: vlang/v

Running:

fn main() {
        mut types := ['game', 'web', 'tools', 'GUI']
        println(types + ['whoot', 'xyz'])
    }

produces You just found a bug. V can't compile this program, but it should. Please create a GitHub issue.

I expect to add the items together in the array.

Most helpful comment

merge_with is less intuitive IMHO because it implies that it's actually _merging_ the arrays (i.e. as in merge sort).

Perhaps join, if a shorter name is required.

All 4 comments

types.append_array([...]) should do what you want.

+ doesn't work with arrays.

Gotcha, then maybe adjust the compiler to not throw this error in this case, that's the only reason i opened this thread :)
Also, append_array does not look like the best name, merge_with sounds much better and it's more intuitive.

merge_with is less intuitive IMHO because it implies that it's actually _merging_ the arrays (i.e. as in merge sort).

Perhaps join, if a shorter name is required.

Fixed:

operator + not defined on `[]string`
Was this page helpful?
0 / 5 - 0 ratings