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

Get the first state using PairWise #579

Open
aytunch opened this issue Apr 18, 2021 · 1 comment
Open

Get the first state using PairWise #579

aytunch opened this issue Apr 18, 2021 · 1 comment

Comments

@aytunch
Copy link

aytunch commented Apr 18, 2021

As stated by the docs:

/// Emits the n-th and n-1th events as a pair.
/// The first event won't be emitted until the second one arrives.

pairwise does not emit the first value, since it is not a pair yet. However this makes using pairwise cumbersome.
Even if the first state emitted is not a pair, I still would like to use it. So maybe we could emit a pair the first time by the help of a dummy constant like pairwise.Empty()

[pairwise.Empty(), 1],     //---->I want to get this
[1, 2],
[2, 3],
etc.

If there is a way to cleanly do this without changing pairwise, I would be very glad to hear your thoughts. Maybe using combine2 somehow?

@frankpepermans
Copy link
Member

I'd just use startWith and then pairWise, then you get a pair on the first event already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants