Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accepting map parameters

Tags:

go

I have a simple function which tests whether a string is an integer

func testInt(str string, m map[bool]) int {
    _,e := strconv.ParseInt(str, 0, 64);
    return m[nil == e] * 7;
}

where the map being passed contains m[true] = 1, m[false] = 0. However, when I attempt to run this Go complains

1: syntax error: unexpected )

Either I cannot pass maps around as parameters in this way or else I am doing this entirely wrong. In any case, I would much appreciate some help

like image 477
DroidOS Avatar asked Mar 05 '15 05:03

DroidOS


1 Answers

A map maps keys to values, using the syntax

map[KeyType]ValueType

(see https://blog.golang.org/go-maps-in-action)

In your function, you have not specified a ValueType, causing this syntax error. It looks like you want a map[bool]int.

like image 185
Vitruvie Avatar answered Nov 10 '22 09:11

Vitruvie