From 3ca3d804490e3c4c6387273995a7988062501971 Mon Sep 17 00:00:00 2001 From: b97tsk Date: Mon, 4 Sep 2023 08:00:00 +0800 Subject: [PATCH] remove AsOperator methods --- buffercount.go | 5 ----- buffercount_test.go | 12 ++++++------ connect.go | 5 ----- connect_test.go | 2 +- merge.go | 5 ----- merge_test.go | 12 ++++++------ share.go | 5 ----- share_test.go | 10 +++++----- throttle.go | 5 ----- throttle_test.go | 20 ++++++++++---------- timeout.go | 5 ----- timeout_test.go | 8 ++++---- 12 files changed, 32 insertions(+), 62 deletions(-) diff --git a/buffercount.go b/buffercount.go index 3d1d3c9a..420d548b 100644 --- a/buffercount.go +++ b/buffercount.go @@ -50,11 +50,6 @@ func (op BufferCountOperator[T]) Apply(source Observable[T]) Observable[[]T] { return bufferCountObservable[T]{source, op.opts}.Subscribe } -// AsOperator converts op to an Operator. -// -// Once type inference has improved in Go, this method will be removed. -func (op BufferCountOperator[T]) AsOperator() Operator[T, []T] { return op } - type bufferCountObservable[T any] struct { Source Observable[T] bufferCountConfig diff --git a/buffercount_test.go b/buffercount_test.go index 0ef21f75..82fda81c 100644 --- a/buffercount_test.go +++ b/buffercount_test.go @@ -13,42 +13,42 @@ func TestBufferCount(t *testing.T) { NewTestSuite[string](t).Case( rx.Pipe2( rx.Just("A", "B", "C", "D", "E"), - rx.BufferCount[string](2).AsOperator(), + rx.BufferCount[string](2), ToString[[]string](), ), "[A B]", "[C D]", "[E]", ErrComplete, ).Case( rx.Pipe2( rx.Just("A", "B", "C", "D", "E"), - rx.BufferCount[string](3).AsOperator(), + rx.BufferCount[string](3), ToString[[]string](), ), "[A B C]", "[D E]", ErrComplete, ).Case( rx.Pipe2( rx.Just("A", "B", "C", "D", "E"), - rx.BufferCount[string](3).WithStartBufferEvery(1).AsOperator(), + rx.BufferCount[string](3).WithStartBufferEvery(1), ToString[[]string](), ), "[A B C]", "[B C D]", "[C D E]", "[D E]", "[E]", ErrComplete, ).Case( rx.Pipe2( rx.Just("A", "B", "C", "D", "E"), - rx.BufferCount[string](3).WithStartBufferEvery(2).AsOperator(), + rx.BufferCount[string](3).WithStartBufferEvery(2), ToString[[]string](), ), "[A B C]", "[C D E]", "[E]", ErrComplete, ).Case( rx.Pipe2( rx.Just("A", "B", "C", "D", "E"), - rx.BufferCount[string](3).WithStartBufferEvery(4).AsOperator(), + rx.BufferCount[string](3).WithStartBufferEvery(4), ToString[[]string](), ), "[A B C]", "[E]", ErrComplete, ).Case( rx.Pipe2( rx.Throw[string](ErrTest), - rx.BufferCount[string](2).AsOperator(), + rx.BufferCount[string](2), ToString[[]string](), ), ErrTest, diff --git a/connect.go b/connect.go index 8ce3a36a..8b859792 100644 --- a/connect.go +++ b/connect.go @@ -45,11 +45,6 @@ func (op ConnectOperator[T, R]) Apply(source Observable[T]) Observable[R] { return connectObservable[T, R]{source, op.opts}.Subscribe } -// AsOperator converts op to an Operator. -// -// Once type inference has improved in Go, this method will be removed. -func (op ConnectOperator[T, R]) AsOperator() Operator[T, R] { return op } - type connectObservable[T, R any] struct { Source Observable[T] connectConfig[T, R] diff --git a/connect_test.go b/connect_test.go index 5e6ca389..b6ddf06f 100644 --- a/connect_test.go +++ b/connect_test.go @@ -27,7 +27,7 @@ func TestConnect(t *testing.T) { ToString[[]int](), ) }, - ).WithConnector(rx.Multicast[int]).AsOperator(), + ).WithConnector(rx.Multicast[int]), ), "[0 5 12 21]", ErrComplete, ) diff --git a/merge.go b/merge.go index 5702621a..b6febce9 100644 --- a/merge.go +++ b/merge.go @@ -120,11 +120,6 @@ func (op MergeMapOperator[T, R]) Apply(source Observable[T]) Observable[R] { return mergeMapObservable[T, R]{source, op.opts}.Subscribe } -// AsOperator converts op to an Operator. -// -// Once type inference has improved in Go, this method will be removed. -func (op MergeMapOperator[T, R]) AsOperator() Operator[T, R] { return op } - type mergeMapObservable[T, R any] struct { Source Observable[T] mergeMapConfig[T, R] diff --git a/merge_test.go b/merge_test.go index f36fa2f0..96e5c4dd 100644 --- a/merge_test.go +++ b/merge_test.go @@ -44,7 +44,7 @@ func TestMerge2(t *testing.T) { rx.Pipe1(rx.Just("C", "D"), AddLatencyToValues[string](2, 4)), rx.Pipe1(rx.Just("E", "F"), AddLatencyToValues[string](1, 3)), ), - rx.MergeAll[rx.Observable[string]]().AsOperator(), + rx.MergeAll[rx.Observable[string]](), ), "E", "C", "A", "F", "D", "B", ErrComplete, ).Case( @@ -54,7 +54,7 @@ func TestMerge2(t *testing.T) { func(v int) rx.Observable[int] { return rx.Pipe1(rx.Just(v), DelaySubscription[int](1)) }, - ).WithConcurrency(3).AsOperator(), + ).WithConcurrency(3), rx.Reduce(0, func(v1, v2 int) int { return v1 + v2 }), ToString[int](), ), @@ -62,19 +62,19 @@ func TestMerge2(t *testing.T) { ).Case( rx.Pipe1( rx.Timer(Step(1)), - rx.MergeMapTo[time.Time](rx.Just("A")).AsOperator(), + rx.MergeMapTo[time.Time](rx.Just("A")), ), "A", ErrComplete, ).Case( rx.Pipe1( rx.Empty[rx.Observable[string]](), - rx.MergeAll[rx.Observable[string]]().AsOperator(), + rx.MergeAll[rx.Observable[string]](), ), ErrComplete, ).Case( rx.Pipe1( rx.Throw[rx.Observable[string]](ErrTest), - rx.MergeAll[rx.Observable[string]]().AsOperator(), + rx.MergeAll[rx.Observable[string]](), ), ErrTest, ).Case( @@ -89,7 +89,7 @@ func TestMerge2(t *testing.T) { sink.Next(rx.Just("E", "F")) sink.Complete() }, - rx.MergeAll[rx.Observable[string]]().AsOperator(), + rx.MergeAll[rx.Observable[string]](), ), "A", "B", ErrTest, ) diff --git a/share.go b/share.go index 6cddf3b8..1564652f 100644 --- a/share.go +++ b/share.go @@ -49,11 +49,6 @@ func (op ShareOperator[T]) Apply(source Observable[T]) Observable[T] { return obs.Subscribe } -// AsOperator converts op to an Operator. -// -// Once type inference has improved in Go, this method will be removed. -func (op ShareOperator[T]) AsOperator() Operator[T, T] { return op } - type shareObservable[T any] struct { mu sync.Mutex source Observable[T] diff --git a/share_test.go b/share_test.go index cbcad7bc..d609cb80 100644 --- a/share_test.go +++ b/share_test.go @@ -16,7 +16,7 @@ func TestShare1(t *testing.T) { rx.Ticker(Step(3)), rx.Scan(-1, func(i int, _ time.Time) int { return i + 1 }), rx.Take[int](4), - rx.Share[int]().AsOperator(), + rx.Share[int](), ) NewTestSuite[int](t).Case( @@ -36,7 +36,7 @@ func TestShare2(t *testing.T) { obs := rx.Pipe3( rx.Ticker(Step(3)), rx.Scan(-1, func(i int, _ time.Time) int { return i + 1 }), - rx.Share[int]().AsOperator(), + rx.Share[int](), rx.Take[int](4), ) @@ -62,7 +62,7 @@ func TestShare3(t *testing.T) { func() rx.Subject[int] { return rx.MulticastReplay[int](&rx.ReplayConfig{BufferSize: 1}) }, - ).AsOperator(), + ), ) NewTestSuite[int](t).Case( @@ -86,7 +86,7 @@ func TestShare4(t *testing.T) { func() rx.Subject[int] { return rx.MulticastReplay[int](&rx.ReplayConfig{BufferSize: 1}) }, - ).AsOperator(), + ), rx.Take[int](4), ) @@ -116,7 +116,7 @@ func TestShare5(t *testing.T) { Observer: rx.Noop[int], } }, - ).AsOperator(), + ), ), ErrTest, ) diff --git a/throttle.go b/throttle.go index 588ca32c..72394653 100644 --- a/throttle.go +++ b/throttle.go @@ -75,11 +75,6 @@ func (op ThrottleOperator[T, U]) Apply(source Observable[T]) Observable[T] { return throttleObservable[T, U]{source, op.opts}.Subscribe } -// AsOperator converts op to an Operator. -// -// Once type inference has improved in Go, this method will be removed. -func (op ThrottleOperator[T, U]) AsOperator() Operator[T, T] { return op } - type throttleObservable[T, U any] struct { Source Observable[T] throttleConfig[T, U] diff --git a/throttle_test.go b/throttle_test.go index 4bb473d6..7010aca7 100644 --- a/throttle_test.go +++ b/throttle_test.go @@ -19,7 +19,7 @@ func TestThrottle(t *testing.T) { func(string) rx.Observable[time.Time] { return rx.Timer(Step(3)) }, - ).AsOperator(), + ), ), "A", "C", "E", ErrComplete, ).Case( @@ -30,7 +30,7 @@ func TestThrottle(t *testing.T) { func(string) rx.Observable[int] { return rx.Empty[int]() }, - ).AsOperator(), + ), ), "A", "B", "C", "D", "E", ErrComplete, ).Case( @@ -44,7 +44,7 @@ func TestThrottle(t *testing.T) { DelaySubscription[int](5), ) }, - ).WithLeading(false).WithTrailing(true).AsOperator(), + ).WithLeading(false).WithTrailing(true), ), ErrComplete, ).Case( @@ -54,7 +54,7 @@ func TestThrottle(t *testing.T) { func(string) rx.Observable[int] { return rx.Throw[int](ErrTest) }, - ).AsOperator(), + ), ), ErrTest, ).Case( @@ -65,7 +65,7 @@ func TestThrottle(t *testing.T) { func(string) rx.Observable[int] { return rx.Throw[int](ErrTest) }, - ).AsOperator(), + ), ), "A", ErrTest, ).Case( @@ -76,7 +76,7 @@ func TestThrottle(t *testing.T) { func(string) rx.Observable[time.Time] { return rx.Timer(Step(9)) }, - ).WithLeading(false).WithTrailing(true).AsOperator(), + ).WithLeading(false).WithTrailing(true), ), "C", "E", ErrComplete, ).Case( @@ -87,28 +87,28 @@ func TestThrottle(t *testing.T) { func(string) rx.Observable[time.Time] { return rx.Timer(Step(9)) }, - ).WithLeading(true).WithTrailing(true).AsOperator(), + ).WithLeading(true).WithTrailing(true), ), "A", "C", "E", ErrComplete, ).Case( rx.Pipe2( rx.Just("A", "B", "C", "D", "E"), AddLatencyToValues[string](0, 2), - rx.ThrottleTime[string](Step(3)).AsOperator(), + rx.ThrottleTime[string](Step(3)), ), "A", "C", "E", ErrComplete, ).Case( rx.Pipe2( rx.Just("A", "B", "C", "D", "E"), AddLatencyToValues[string](0, 4), - rx.ThrottleTime[string](Step(9)).WithLeading(false).WithTrailing(true).AsOperator(), + rx.ThrottleTime[string](Step(9)).WithLeading(false).WithTrailing(true), ), "C", "E", ErrComplete, ).Case( rx.Pipe2( rx.Just("A", "B", "C", "D", "E"), AddLatencyToValues[string](0, 4), - rx.ThrottleTime[string](Step(9)).WithLeading(true).WithTrailing(true).AsOperator(), + rx.ThrottleTime[string](Step(9)).WithLeading(true).WithTrailing(true), ), "A", "C", "E", ErrComplete, ) diff --git a/timeout.go b/timeout.go index 9dbb35cc..996ceeec 100644 --- a/timeout.go +++ b/timeout.go @@ -46,11 +46,6 @@ func (op TimeoutOperator[T]) Apply(source Observable[T]) Observable[T] { return timeoutObservable[T]{source, op.opts}.Subscribe } -// AsOperator converts op to an Operator. -// -// Once type inference has improved in Go, this method will be removed. -func (op TimeoutOperator[T]) AsOperator() Operator[T, T] { return op } - type timeoutObservable[T any] struct { Source Observable[T] timeoutConfig[T] diff --git a/timeout_test.go b/timeout_test.go index a75ffa8c..efccd87d 100644 --- a/timeout_test.go +++ b/timeout_test.go @@ -14,28 +14,28 @@ func TestTimeout(t *testing.T) { rx.Pipe2( rx.Just("A", "B", "C"), AddLatencyToValues[string](1, 1), - rx.Timeout[string](Step(2)).AsOperator(), + rx.Timeout[string](Step(2)), ), "A", "B", "C", ErrComplete, ).Case( rx.Pipe2( rx.Just("A", "B", "C"), AddLatencyToValues[string](1, 3), - rx.Timeout[string](Step(2)).AsOperator(), + rx.Timeout[string](Step(2)), ), "A", rx.ErrTimeout, ).Case( rx.Pipe2( rx.Just("A", "B", "C"), AddLatencyToValues[string](2, 2), - rx.Timeout[string](Step(1)).WithFirst(Step(3)).AsOperator(), + rx.Timeout[string](Step(1)).WithFirst(Step(3)), ), "A", rx.ErrTimeout, ).Case( rx.Pipe2( rx.Just("A", "B", "C"), AddLatencyToValues[string](1, 3), - rx.Timeout[string](Step(2)).WithObservable(rx.Throw[string](ErrTest)).AsOperator(), + rx.Timeout[string](Step(2)).WithObservable(rx.Throw[string](ErrTest)), ), "A", ErrTest, )