generated from snivilised/astrolib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rx): add zip from iterable operator (#220)
- Loading branch information
1 parent
ad4607c
commit 43ebec2
Showing
9 changed files
with
219 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package rx_test | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/fortytw2/leaktest" | ||
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok | ||
"github.com/snivilised/lorax/rx" | ||
) | ||
|
||
var _ = Describe("Observable operator", func() { | ||
Context("ZipFromIterable", func() { | ||
When("source and other observers same length", func() { | ||
It("🧪 should: emit zipped elements", func() { | ||
// rxgo: Test_Observable_ZipFromObservable | ||
defer leaktest.Check(GinkgoT())() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
obs1 := testObservable[int](ctx, 1, 2, 3) | ||
obs2 := testObservable[int](ctx, 10, 20, 30) | ||
zipper := func(_ context.Context, a, b rx.Item[int]) (int, error) { | ||
return a.V + b.V, nil | ||
} | ||
zip := obs1.ZipFromIterable(obs2, zipper) | ||
rx.Assert(ctx, zip, rx.HasItems[int]{ | ||
Expected: []int{11, 22, 33}, | ||
}) | ||
}) | ||
}) | ||
|
||
When("source observer longer than other", func() { | ||
It("🧪 should: omit zip from trailing items", func() { | ||
// rxgo: Test_Observable_ZipFromObservable_DifferentLength1 | ||
defer leaktest.Check(GinkgoT())() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
obs1 := testObservable[int](ctx, 1, 2, 3) | ||
obs2 := testObservable[int](ctx, 10, 20) | ||
zipper := func(_ context.Context, a, b rx.Item[int]) (int, error) { | ||
return a.V + b.V, nil | ||
} | ||
zip := obs1.ZipFromIterable(obs2, zipper) | ||
rx.Assert(ctx, zip, rx.HasItems[int]{ | ||
Expected: []int{11, 22}, | ||
}) | ||
}) | ||
}) | ||
|
||
When("source observer shorter than other", func() { | ||
It("🧪 should: omit zip from trailing items", func() { | ||
// rxgo: Test_Observable_ZipFromObservable_DifferentLength2 | ||
defer leaktest.Check(GinkgoT())() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
obs1 := testObservable[int](ctx, 1, 2) | ||
obs2 := testObservable[int](ctx, 10, 20, 30) | ||
zipper := func(_ context.Context, a, b rx.Item[int]) (int, error) { | ||
return a.V + b.V, nil | ||
} | ||
zip := obs1.ZipFromIterable(obs2, zipper) | ||
rx.Assert(ctx, zip, rx.HasItems[int]{ | ||
Expected: []int{11, 22}, | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.