Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rx Let function

Ive been investiging the Rx library and have tried to replicate the example from the following video...

http://channel9.msdn.com/blogs/j.van.gogh/writing-your-first-rx-application

it all works (with some modifications to things that have been changed/deprecated) up until he used...

.Let(mm => ...)

This throws a compiler error saying that there is no definition for let, so I assume that Let has been changed to something else, or removed completely, but I cant find any solutions from a googling.

So does anybody know what to use in this instance?

like image 547
electricsheep Avatar asked Aug 25 '11 12:08

electricsheep


2 Answers

As per Jim Wooley's suggestion.

I think the code you are looking at is

var q = from start in mouseDown
  from delta in mouseMove.StartWith(start).Until(mouseUp)
    .Let(mm=> mm.Zip(mm.Skip(1), (prev, curr) =>
              new { X = curr.X - prev.X, Y = curr.Y - prev.Y}))
  select delta;

Remember that was written in 2009 and Rx has move along some since then. I think this is what you want. I think the Let is a feature you want to avoid (even if available to you) in Rx as it can encourage side effects. Use transformation with Select instead. In the case below, the let is just not needed.

//Gets the delta of positions.
var mouseMovements = mouseMove.Zip(mouseMove.Skip(1), (prev, curr) =>
              new { X = curr.X - prev.X, Y = curr.Y - prev.Y}));
//Only streams when mouse is down
var dragging = from md in mouseDown
               from mm in mouseMovement.TakeUntil(mouseUp)
               select mm;
like image 53
Lee Campbell Avatar answered Sep 28 '22 10:09

Lee Campbell


Try using another .Select and project a type that includes both your new variable and the incoming observable value.

like image 39
Jim Wooley Avatar answered Sep 28 '22 11:09

Jim Wooley