Rx – for beginners (part 5): marble diagrams, select and where
the series TOC can found here.
this post will focus on marble diagrams which is used for visualizing IObservable stream.
on this post we will visualize the select and where clause, while in the
upcoming posts we will discuss other operations that can be
used to upon IObservable streams.
What should we visualize?
the event stream should visualize the following:
- on next
- on error
- on complete
How should we read the diagram?
marble diagram can have one or more horizontal line.
- each horizontal line present the timeline of single IObservable stream.
- the ellipse present single occurrence of new value event (on next).
- the vertical line present the end of the stream sequence (on complete).
- the X sign present exception (on error).
The hidden assumption used by the Rx framework is that the IObservable stream
should stop either on complete or on error.
How can we draw select clause using the marble diagram?
line 2, creating IObservable stream that increment the projected value each second.
line 5, is using Linq statement to convert the stream into negative value.
line 8, subscribe to the stream and write it to the console.
the result is shown in the following image.
the marble diagrams for the above snippet will look like the following diagram:
the marble diagrams show the construction of new IObservable stream using the select operation.
the vertical arrow present the transition from the source stream into the destination stream.
as the case with IEnumerable the select statement is extension method which
can be used on any IObservable stream, we will get same result for the following code:
Where clause marble diagram?
the where clause of the following snippet:
will be present:
marble diagrams is how stream manipulation can be visualize.
we already surveyed the select and where operations, and we will continue
with other operation in the upcoming posts.