Created
February 1, 2022 09:36
-
-
Save AntonStoeckl/8d65fe1eb580926a2a91be36dda6f3bc to your computer and use it in GitHub Desktop.
Example for blog post: Go bits: Magic with functions
This file contains hidden or 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 basics | |
// IsBigger is a plain function that compares two integers | |
// and return true if the first is bigger than the second ;-) | |
func IsBigger(first, second int) bool { | |
return first > second | |
} | |
// Compare is a higher order function that compares two integers via a function | |
// that is passed in as the third parameter using explicit annotation, | |
// so the full function signature is annotating the type of the parameter | |
func Compare(first, second int, compareFn func(first, second int) bool) bool { | |
return compareFn(first, second) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment