ReactiveX / RxSwift

Reactive Programming in Swift
MIT License
24.32k stars 4.17k forks source link

Proposal, add overlapping buffers. #2593

Open danielt1263 opened 4 months ago

danielt1263 commented 4 months ago

I always thought it odd that the overlapping buffers which are offered in the core .NET Rx implementation and documented in the Introduction to Rx book are not part of RxSwift. I've had personal implementations that I wrote back in 2019, and I was thinking it would be nice to finally add them to the library. Maybe I should add them to the RxSwiftExt library instead?

What do you all think?

freak4pc commented 4 months ago

Can you share how that use case would look? Maybe example input / output so I can better understand ?

In general the aim of the library is to add mainly useful operators and not just theoretically useful ones so would be great finding the use case for such a new operator

Thanks for the suggestion!

danielt1263 commented 4 months ago

There is an example in the book (that I linked, but you have to scroll down a ways) that uses an overlapping buffer to calculate the average speed of a vessel, and I've used it for that sort of thing in the past.

I have also used it to smooth out jitter while reading the accelerometer input.

Lastly, an overlapping buffer comes in handy when you want the two most recent values emitted from an observable. It's cleaner than doing the whole share/skip/zip dance. Instead, you just do .buffer(count: 2, skip: 1).