Skip to content

Commit aa17f03

Browse files
committed
Updated
1 parent be90a02 commit aa17f03

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

golang-maps.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Title: Golang: Maps
22
Tags: golang
33

4-
A map is a key value store of data. You define it using the map keyword, the type type in brackets, then the value type:
4+
A map is a key value store of data. You define it using the map keyword, the key type in brackets, then the value type:
55

66
var aMap map[string]string
77

@@ -30,9 +30,11 @@ If your values are slices, you can append an item, even if the value is nil, wit
3030
myMap["a"] = append(myMap["a"], "z")
3131
// At this point myMap["a"] is ["z"]
3232

33-
Your key be any simple types and structs (containing only comparable types), interface types, channels and more.
33+
Your key be any simple type. In addition, structs (containing only comparable types), interface types, channels and more.
3434

35-
You can use struct keys and simple values to simplify adding data to a map. With complex types as values, such as maps or slices, you will need to check they are not there and possibly allocate space. Instead use a key struct, encoding the data in that struct, and have the value as a simple type like a number.
35+
You can use struct keys and simple values to simplify adding data to a map. With complex types as values, such as maps or slices, you will need to check they are not there and possibly allocate space.
36+
37+
Instead use a key struct, encoding the data in that struct, and have the value as a simple type like a number.
3638

3739
aMap[SomeStruct{"hi", 123}]++
3840
// The downside here is your lookup will need to have all that data inside

0 commit comments

Comments
 (0)