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 filter operator (#172)
- Loading branch information
1 parent
1153d0b
commit 8a8da81
Showing
3 changed files
with
95 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package rx_test | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/fortytw2/leaktest" | ||
. "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo ok | ||
"github.com/snivilised/lorax/rx" | ||
) | ||
|
||
func even(item rx.Item[int]) bool { | ||
return item.V%2 == 0 | ||
} | ||
|
||
var _ = Describe("Observable operator", func() { | ||
Context("Filter", func() { | ||
When("principle", func() { | ||
It("🧪 should: return filtered items", func() { | ||
// rxgo: Test_Observable_Filter | ||
defer leaktest.Check(GinkgoT())() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
obs := testObservable[int](ctx, 1, 2, 3, 4).Filter(even) | ||
rx.Assert(ctx, obs, | ||
rx.HasItems[int]{ | ||
Expected: []int{2, 4}, | ||
}, | ||
rx.HasNoError[int]{}, | ||
) | ||
}) | ||
}) | ||
|
||
Context("Parallel", func() { | ||
When("foo", func() { | ||
It("🧪 should: return filtered items", func() { | ||
// rxgo: Test_Observable_Filter_Parallel | ||
defer leaktest.Check(GinkgoT())() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
obs := testObservable[int](ctx, 1, 2, 3, 4).Filter(even, | ||
rx.WithCPUPool[int](), | ||
) | ||
rx.Assert(ctx, obs, | ||
rx.HasItemsNoOrder[int]{ | ||
Expected: []int{2, 4}, | ||
}, | ||
rx.HasNoError[int]{}, | ||
) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
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