func TestIntExample(t *testing.T) { addTwo := func(x int) result_int.Result { return result_int.Success(2 + x) } success := result_int.Success(7).Bind(addTwo) assert.Equal(t, result_int.Success(9), success) err := errors.New("The error") failure := result_int.Failure(err).Bind(addTwo) assert.Equal(t, result_int.Failure(err), failure) }
func TestDeferOnFailure(t *testing.T) { executed := false err := errors.New("The error") result_int. Failure(err). Defer(func(_ int) { executed = true }). Err() assert.Equal(t, false, executed) }
func TestDeferIsPreserved(t *testing.T) { executed := false var got int err := errors.New("The error") result_int. Success(24). Defer(func(x int) { executed = true; got = x }).Bind( func(x int) result_int.Result { return result_int.Failure(err) }). Err() assert.Equal(t, true, executed) assert.Equal(t, 24, got) }