Converting entities to streams (IObservable<T>)

The following constructs can be converted to a sequence source. IObservable<T> can be generated from the following:

  • Events
  • Delegates
  • Tasks
  • IEnumerable<T>
  • Asynchronous programming model

Converting events into stream

We have now understood how one can convert an IEnumerable<T>-based pull program to an IObservable<T>/IObserver<T>-based push program. In real life, the event source is not as simple as we found in the number stream example given previously. Let us see how we can convert a MouseMove event into a stream with a small WinForms program:

 static void Main() { var mylabel = new Label(); var myform = new Form { Controls = { mylabel } }; IObservable<EventPattern<MouseEventArgs>> mousemove = Observable. ...

Get .NET Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.