create a map with a value of type rune in go

To create a map with a value of type rune in Go, you can use the built-in "make" function as follows:

main.go
myMap := make(map[string]rune)
31 chars
2 lines

This creates an empty map variable named "myMap" with string keys and rune values. You can then use this map to store and retrieve values of type rune. Here's an example of how to set and get a value for a key in this map:

main.go
myMap["myKey"] = 'a'
fmt.Println(myMap["myKey"])
49 chars
3 lines

In this example, the value for the key "myKey" is set to the rune value of 'a'. The "fmt.Println" statement will output this value when executed.

You can also initialize a map with values using the map literal syntax. Here's an example of how to create a map with pre-defined values of type rune:

main.go
myMap := map[string]rune{
    "myKey1": 'a',
    "myKey2": 'b',
    "myKey3": 'c',
}
85 chars
6 lines

This creates a map named "myMap" with three key-value pairs where the keys are strings and the values are rune values. You can then access these values by using their corresponding keys like so:

main.go
fmt.Println(myMap["myKey2"])
29 chars
2 lines

This will output the value associated with "myKey2", which is 'b' in this case.

gistlibby LogSnag