-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example #9: compare for various types (no overloading)
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
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
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")) | ||
} |