Skip to content

Instantly share code, notes, and snippets.

@AntonStoeckl
Created February 1, 2022 09:49
Show Gist options
  • Save AntonStoeckl/f00c4e891c5c0f1eafae55c0983dc776 to your computer and use it in GitHub Desktop.
Save AntonStoeckl/f00c4e891c5c0f1eafae55c0983dc776 to your computer and use it in GitHub Desktop.
Example for blog post: Go bits: Magic with functions
package basics_test
import (
"testing"
"github.com/matryer/is"
. "go-bits/magic-with-functions/basics"
)
// Passing a regular function as a value to a higher order function
// with a function type annotation
func Test_OtherCompare1(t *testing.T) {
// Arrange
shouldBe := is.New(t)
// Act
result := OtherCompare(2, 1, IsBigger)
// Assert
shouldBe.True(result)
}
// Passing a lambda function as a value to a higher order function
// with a function type annotation
func Test_OtherCompare_2(t *testing.T) {
// Arrange
shouldBe := is.New(t)
isBigger := func(first, second int) bool {
return first > second
}
// Act
result := OtherCompare(2, 1, isBigger)
// Assert
shouldBe.True(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment