Rx Workshop: Reactive Coincidence
- Posted: Jul 11, 2011 at 12:05 PM
- 24,495 Views
- 11 Comments
Download
How do I download the videos?
- To download, right click the file type you would like and pick “Save target as…” or “Save link as…”
Why should I download videos from Channel9?
- It's an easy way to save the videos you like locally.
- You can save the videos in order to watch them offline.
- If all you want is to hear the audio, you can download the MP3!
Which version should I choose?
- If you want to view the video on your PC, Xbox or Media Center, download the High Quality WMV file (this is the highest quality version we have available).
- If you'd like a lower bitrate version, to reduce the download time or cost, then choose the Medium Quality WMV file.
- If you have a Zune, WP7, iPhone, iPad, or iPod device, choose the low or medium MP4 file.
- If you just want to hear the audio of the video, choose the MP3 file.
Right click “Save as…”
- High Quality WMV (PC, Xbox, MCE)
- MP3 (Audio only)
- Mid Quality WMV (Lo-band, Mobile)
- High Quality MP4 (iPad, PC)
- MP4 (iPod, Zune HD)
Learn how to model events with duration and how to use the LINQ Join operator to express complex queries involving coincidence.
Comments Closed
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
awsome stuff..
Am I allowed to post the solution of the challange?
Benny
Here is what I came up with
var query = Observable.Join( mouseDown, mouseMove, _ => mouseUp, _ => Observable.Empty<Unit>(), (_, r) => r) .Publish(evt => evt.Zip(evt.Skip(1), (previous, current) => Subtract(current, previous)));I am having difficulty translating this into query comprehension syntax. Anyone figure that out? Thanks.
Alright here is a working query comprehension version
var query = from start in mouseDown join move in mouseMove on mouseUp equals Observable.Empty<Unit>() into moveGroup let drag = moveGroup.Zip(moveGroup.Skip(1), (prev, curr) => Subtract(curr, prev)) from delta in drag select delta;Still curious if this could be cleaner. Thanks.
Here is my solution:
var query = Observable.Join(
mouseDown,
mouseMove.Buffer(2),
_ => mouseUp,
m => Observable.Empty<Unit>(),
(_, r) => Subtract(r.Last(),r.First()));
I think my solution is close to the optimum!?
But I had to modify the subscibtion from deltas to absolute points.
var query = mouseDown.Join(mouseMove, l => mouseUp, r => Observable.Empty<Point>(),(l,r)=> Subtract(r,l)); query.Subscribe(pos=> { Canvas.SetLeft(image, pos.X); Canvas.SetTop(image, pos.Y); });I notied there is a bug when releasing the mouse button from outside of the window. Here is a fix that will merge mouseUp and mouseLeave to accomplish the task. What is normal UI guidance for drag and drop when going outside the window? Thanks.
var mouseLeave = from evt in Observable.FromEventPattern<MouseEventHandler, MouseEventArgs>(h => MouseLeave += h, h => MouseLeave -= h) select evt.EventArgs.GetPosition(this); var query = from start in mouseDown join move in mouseMove.Buffer(2) on mouseUp.Merge(mouseLeave) equals Observable.Empty<Unit>() select Subtract(move.Last(), move.First());Hey what happened to the challenges. They are showing up 404. I was trying to dowload again. Thanks.
Here is my (edited) suggestion:
The Subtract method is not needed.
Here is a solution that uses the Scan method:
var query = mouseDown.Join(
mouseMove
.Scan(new { Prev = new Point(), Delta = new Point() },
(current, next) => new { Prev = next, Delta = Subtract(next, current.Prev) })
.Select(x => x.Delta),
down => mouseUp,
delta => Observable.Empty<Unit>(),
(down, delta) => delta);
Remove this comment
Remove this thread
close