Skip to content

Instantly share code, notes, and snippets.

@pedrobertao
Created August 31, 2023 10:05
Show Gist options
  • Save pedrobertao/3f7b32dcbeacefdfa7ede2f64270bfdf to your computer and use it in GitHub Desktop.
Save pedrobertao/3f7b32dcbeacefdfa7ede2f64270bfdf to your computer and use it in GitHub Desktop.
cmp package in golang
package main
import (
"cmp"
"fmt"
)
func main() {
var num, num2, num3 int64 = 1, 2, 1
var str, str2, str3 = "ab", "abc", "ab"
r := cmp.Compare[int64](num, num2)
r2 := cmp.Compare[int64](num, num3)
r3 := cmp.Less[string](str, str2)
r4 := cmp.Less[string](str, str3)
fmt.Println("Num is less than Num2: ", r <= 0)
fmt.Println("Num is equal to Num3: ", r2 >= 0)
fmt.Println("Num2 is greater than Num: ", r2 >= 0)
fmt.Println("")
fmt.Println("Str is less than Str2: ", r3)
fmt.Println("Str is less than Str3 ", r4)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment