aboutsummaryrefslogtreecommitdiff
path: root/content/maps/people.go
blob: ff5d9e3a42183c3212a5f98b582f1121c70f832f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2013 The Go Authors.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build OMIT

package main

import "fmt"

func main() {
	// START1 OMIT
	type Person struct {
		Name  string
		Likes []string
	}
	var people []*Person

	likes := make(map[string][]*Person) // HL
	for _, p := range people {
		for _, l := range p.Likes {
			likes[l] = append(likes[l], p) // HL
		}
	}
	// END1 OMIT

	// START2 OMIT
	for _, p := range likes["cheese"] {
		fmt.Println(p.Name, "likes cheese.")
	}
	// END2 OMIT

	fmt.Println(len(likes["bacon"]), "people like bacon.")
}