Skip to content

Error: cannot define new methods on non-local type []string #21802

Closed Answered by Delta456
hidsh asked this question in Questions and Answers
Discussion options

You must be logged in to vote

You need to make an alias

type Alias = []string

fn (arr Alias) mapconcat() string {
    mut ret := ''
    for s in arr {
        ret += s
    }
    return ret
}

arr := Alias(['aaa', 'bbb'])
s := Alias(arr.map(|x| x.to_upper())).mapconcat()

println(s)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@hidsh
Comment options

@Delta456
Comment options

Answer selected by hidsh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants