Created
February 1, 2022 09:49
-
-
Save AntonStoeckl/f00c4e891c5c0f1eafae55c0983dc776 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_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