I would like to buffer items in a sequence according to a condition. The problem is that this condition depends on the items that are processed.
Let me put an example:
Given this:
new[] { 1, 3, 5, 7, 2, 4, 6, 8, 1 };
- If n is odd, stop buffering
- If n is even, start buffering
This way, the result sequence should be:
{ 1 }
{ 3 }
{ 5 }
{ 7 }
{ 2, 4, 6, 8 }
{ 1 }
I've tried variations of this without success:
var boundaries = origin.Select(x => x % 2 != 0).DistinctUntilChanged();
var result = origin.Buffer(boundaries);