package main
import "fmt"
func main() {
// Set of strings — value type is struct{}, takes ZERO bytes per entry
seen := make(map[string]struct{})
seen["alice"] = struct{}{}
seen["bob"] = struct{}{}
// Lookup
if _, ok := seen["alice"]; ok {
fmt.Println("alice was seen")
}
// Compare to map[string]bool — bool takes 1 byte per entry; struct{} 0
fmt.Println(len(seen)) // 2
// Signal channel — no data, just "something happened"
done := make(chan struct{})
go func() {
// ... work ...
done <- struct{}{}
}()
<-done
fmt.Println("done received")
}
Create a free account and build your private vault. Share publicly whenever you want.