Similar to this Flutter question I want to nest Stream
s.
In Flutter, this can be achieved easily by nesting StreamBuilder
s, however, I do not want to use widgets. Instead, I want to solve the problem in Dart alone. (nesting here means that one stream depends on the values from another stream and these should be combined)
Let me illustrate the problem:
Stream streamB(String a);
streamA: 'Hi' --- 'Hello' ---- 'Hey'
As you can see, I have a streamA
that continuously emits events and a streamB
that arises from the events that streamA
emits. In a streamC
, I want to be updated about every event from streamB
.
Regular stream mapping
If I had valueB
instead of streamB
, I could simply use streamA.map((event) => valueB(event))
, however, Stream.map
can only handle synchronous values.
There is also Stream.asyncMap
, however, that only works for Future
s.
Then, there is also Stream.expand
, but that works only for synchronous iterables.