fn: add Sink to Result

This commit is contained in:
Keagan McClelland
2024-08-14 15:22:30 -07:00
parent 5dec35426c
commit 9bbd327a10
2 changed files with 36 additions and 0 deletions

View File

@@ -70,3 +70,29 @@ func TestPropTransposeResOptInverts(t *testing.T) {
require.NoError(t, quick.Check(f, nil))
}
func TestSinkOnErrNoContinutationCall(t *testing.T) {
called := false
res := Err[uint8](errors.New("err")).Sink(
func(a uint8) error {
called = true
return nil
},
)
require.False(t, called)
require.NotNil(t, res)
}
func TestSinkOnOkContinuationCall(t *testing.T) {
called := false
res := Ok(uint8(1)).Sink(
func(a uint8) error {
called = true
return nil
},
)
require.True(t, called)
require.Nil(t, res)
}