'RxDart convert Stream based on previous value

Lets say I have a Stream that emits a List followed by single elements like:

Stream.fromIterable([
  [1, 2, 3],
  4,
  5,
]);

How to convert it to a Stream that updates the previous element with current value and emits:

[1, 2, 3],
[1, 2, 3, 4],
[1, 2, 3, 4, 5],


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source