Get maximum int key from a map of ints This code snippet gets the maximum int out of a map's keys

func max(numbers map[int]bool) int {
    var maxNumber int
    for n := range numbers {
        maxNumber = n
        break
    }
    for n := range numbers {
        if n &gt; maxNumber {
            maxNumber = n
        }
    }
    return maxNumber
}
You could remove the first range by initialising maxNumber with math.MinInt(32|64) depending on the architecture. E.g. on 32-bit systems:

func max(numbers map[int]bool) (maxNumber int) {
    maxNumber = math.MinInt32
    for n := range numbers {
        if n &gt; maxNumber {
            maxNumber = n
        }
    }
    return maxNumber
}


You can make it work with either system using build tags.