-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Operator for buffer until stream #590
Comments
Hi @joeljeske , I think that we'll need to figure out how to upscale those operators. I don't think it would be a good idea to increase number of operators in base implementation because Swift generates a lot bigger frameworks then other implementations do. Can you explain me some context why do you need it so I can get a feeling how common is that use case? |
Sure that makes sense. I am wanting to buffer a stream of items until a user clicks a button. Essentially, it is not a time-based buffer or a item-count-based buffer but an event-based-buffer. The operator would emit a collection of the items containing 0 or more previously emitted items. I am not partial to having a separate buffer implementation or an overloaded buffer implementation as long as I could ignore the time based boundary and the count based boundary. Here are the docs for the RxJava |
Hi @joeljeske, I usually try to fit all of these problems to same model:
It's usually handy to define something like a convenience // if emit != nil, then emits an item
public func scanAndMaybeEmit<State, Emit>(state: State, accumulator: (State, E) throws -> (State, Emit?)) -> Observable<Emit> {
return self.scan((state, nil)) { stateEmitPair, element in
return try accumulator(stateEmitPair.0, element)
}
.flatMap { stateEmitPair in
return stateEmitPair.1.map(Observable.just) ?? Observable.empty()
}
} Then you have two commands that you merge that controls that
That should give you some ideas :) I always mentally go to this "redux" like model because it's applicable in enormous number of cases, and there is absolutely no way you will run into performance issues if you do this on UI events, etc :) |
We are probably going to start a new project in RxSwiftCommunity with more additional operators, so we might push this there. |
Yeah, I think we currently don't plan to implement that operator in the core library, but maybe we'll be able to include it with time in some other library inside RxSwiftCommunity. We can probably close this for now. |
you could use this implementation for your needs |
I have a use case for a similar operator and was hoping for a pointer on a solution @kzaher . I have posted a more detailed question here: http://stackoverflow.com/questions/39184148/buffer-observable-until-another-observable-completes The gist of it is basically: I have an Edit: |
Hi guys, I am also looking for a buffer with a flexible closing condition and posted a simple implementation on stackoverflow (a little different from what @colinmorelli was asking): If anybody is interested, I would love to hear some feedback, especially if there are any leaks in my implementation or if I am violating any Rx contracts. Thanks :) |
@mikumi 's answer on SO seams to solve the case but I am still curious about the potential leaks it may cause on complex chains. There are also other |
Here is the one I mentioned earlier. Requires review: http://stackoverflow.com/a/43410595/1853938 |
Here's one based on RxJS's |
From RxSwiftCommunity/RxSwiftExt: https://github.com/RxSwiftCommunity/RxSwiftExt/blob/master/Source/RxSwift/pausableBuffered.swift |
Is there a buffer-like operator that buffers until another stream emits an item? I know other implementations support a
buffer-until-stream
operator but was unable to find such an operator in RxSwift. If there is not an operator like this, can it be added?The text was updated successfully, but these errors were encountered: