-
Hello, I'm trying to create overlapping windows. Given a sequence 1..10, I want to create (1,2), (2,3), ..., (9,10) var source = Observable.Range(1, 10);
source
.Window(2, 1)
.Subscribe(w =>
{
Console.WriteLine("new window:");
w.Subscribe(x =>
{
Console.WriteLine(x);
});
}); outputs
This output doesn't make sense to me. Am I doing something wrong? For comparison, a non-overlapping window works the way I expect: var source = Observable.Range(1, 10);
source
.Window(2, 2)
.Subscribe(w =>
{
Console.WriteLine("new window:");
w.Subscribe(x =>
{
Console.WriteLine(x);
});
});
|
Beta Was this translation helpful? Give feedback.
Answered by
akarnokd
Apr 23, 2022
Replies: 1 comment
-
The misunderstanding comes from var source = Observable.Range(1, 10);
var counter = new int[1];
source
.Window(2, 1)
.Subscribe(w =>
{
Console.WriteLine("new window:");
var id = ++counter[i];
w.Subscribe(x =>
{
Console.Write(id);
Console.Write(": ");
Console.WriteLine(x);
});
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
dotnetdan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The misunderstanding comes from
WriteLine
where it is not obvious which source value ended up in which window in your code.