Skip to content

Instantly share code, notes, and snippets.

@AntonStoeckl
Created February 1, 2022 09:36
Show Gist options
  • Save AntonStoeckl/8d65fe1eb580926a2a91be36dda6f3bc to your computer and use it in GitHub Desktop.
Save AntonStoeckl/8d65fe1eb580926a2a91be36dda6f3bc to your computer and use it in GitHub Desktop.
Example for blog post: Go bits: Magic with functions
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