Skip to content

Commit

Permalink
Example #9: compare for various types (no overloading)
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Jun 13, 2022
1 parent f7c6b1e commit 1ab48c6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lesson8/09_comparable_variable_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// In Go version < 1.18 it was not easy to make variant
// of such function for multiple data types.

package main

import "fmt"

func compareInts(x int, y int) bool {
return x < y
}

func compareFloats(x float64, y float64) bool {
return x < y
}

func compareStrings(x string, y string) bool {
return x < y
}

func main() {
fmt.Println(compareInts(1, 2))
fmt.Println(compareFloats(1.5, 2.6))
fmt.Println(compareStrings("foo", "bar"))
}

0 comments on commit 1ab48c6

Please sign in to comment.