Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwitchMap operator #362

Open
karneges opened this issue Apr 25, 2022 · 0 comments
Open

SwitchMap operator #362

karneges opened this issue Apr 25, 2022 · 0 comments
Assignees
Labels
question Question regarding how RxGo is working etc.

Comments

@karneges
Copy link

Hello! One of the best RX operators is SwitchMap, it looks like FlatMap, but this operator stops previous observable
https://rxjs.dev/api/operators/switchMap

It is imperative to be able to complete the previous observable
docs:
Returns an Observable that emits items based on applying a function that you supply to each item emitted by the source Observable, where that function returns an (so-called "inner") Observable. Each time it observes one of these inner Observables, the output Observable begins emitting the items emitted by that inner Observable. When a new inner Observable is emitted, switchMap stops emitting items from the earlier-emitted inner Observable and begins emitting items from the new one. It continues to behave like this for subsequent inner Observables.

Or maybe you can provide some advice?
Example case:

func main() {
	observable := rxgo.Just(1, 2, 3)().FlatMap(func(i rxgo.Item) rxgo.Observable {
		println("new item", i.V.(int))
		return rxgo.Interval(rxgo.WithDuration(time.Second * 1))
	})
	for el := range observable.Observe() {
		println(el.V.(int))
	}
}

I want to make a new observable each time after Just or other Observable creators emit a new value. In this case nice to unsubscribe from interval and create new observable

P.S Well, as I can see the flat map operator doesn't work too
output

new item 1
0
1
2
3
4
5
6
@karneges karneges added the question Question regarding how RxGo is working etc. label Apr 25, 2022
@si3nloong si3nloong mentioned this issue Aug 27, 2022
8 tasks
@si3nloong si3nloong linked a pull request Aug 27, 2022 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question regarding how RxGo is working etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants