-
Notifications
You must be signed in to change notification settings - Fork 8
richardszalay edited this page May 20, 2011
·
6 revisions
Pipes a composed sequence to be mapped through a function so it can be used multiple times
function let(func : Function) : IObservable.<T>
Where func is function (input : IObservable.<T>) : IObservable.<T>
Let allows a sequence to be reused without having to assign it to a local variable first.
The returned sequence completes if the source sequence completes
The returned sequence errors if the source sequence errors or if func throws an error
xs ─┐
f()
└───o─────o──/
│ │ │
zs ─────o─────o──/
IObservable.<T>
Observable.range(1, 5)
.map(function (x: int) : int { return x * 2; })
.let(function(source : IObservable) : IObservable
{
// 'source' is 'range.select()', but we can use it as a unit here
return source.zip(source.skip(1), function(x:int, y:int) : int
{
return x * y;
});
});
.subscribe(
function(x:int) : void { trace(x); },
function() : void { trace("Completed"); }
);
// Trace output is:
// 8
// 24
// 48
// 80
// Completed