Last active
April 10, 2022 15:55
-
-
Save Chever-John/534ad65c9b842ab4cc2bc1b69021af10 to your computer and use it in GitHub Desktop.
Using map[...]bool to simulate a set in golang.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
var validNames = map[string]bool{ | |
"blue": true, | |
"yellow": true, | |
} | |
func main() { | |
if validNames["blue"] { | |
fmt.Println("blue is ok!") | |
} | |
if validNames["green"] { | |
fmt.Println("green is ok!") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment