3

I have a stream for the state of the left mouse button:

var leftMouseButton = mouse.Select(x => x.LeftButton).DistinctUntilChanged();

I then Window this to give me an observable of observables representing drags of the mouse:

var leftMouseDrag = mouse
    .Select(mouseState => new Point(mouseState.X, mouseState.Y))
    .DistinctUntilChanged()
    .Window(leftMouseButton.Where(x => x == ButtonState.Pressed), x => leftMouseButton.Where(y => y != x));

Now I would like to make a stream off of leftMouseDrag that gives lists of points. Every time the user completes a drag (LMB down -> move -> LMB up) it should fire with the list of positions that the mouse moved through.

How do I take an IObservable<IObservable<Point>> and turn it into an IObservable<IEnumerable<Point>>?

sdgfsdh
  • 33,689
  • 26
  • 132
  • 245

1 Answers1

1

Change your Window operator to Buffer operator (this overload).

The operator produces IObservable<IList<T>> , in which IList is of IEnumerable


Alternative solution based on OP comment:

var leftMouseDragLists = leftMouseDrag.SelectMany(i => i.ToList());
supertopi
  • 3,469
  • 26
  • 38
  • Sorry I didn't mention in my question that I am using `leftMouseDrag` elsewhere so I would like to keep it unchanged. – sdgfsdh Jul 04 '16 at 10:07