-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZip 1.linq
23 lines (20 loc) · 1008 Bytes
/
Zip 1.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<Query Kind="Statements">
<Reference><ApplicationData>\LINQPad\Samples\Programming Reactive Extensions and LINQ\System.Reactive.dll</Reference>
<Namespace>System.Reactive</Namespace>
<Namespace>System.Reactive.Linq</Namespace>
</Query>
/* Zip 1:
*
* Zip allows us to merge two Observables, just like its Linq counterpart. Zip
* creates two "slots" - whenever both slots have an item, it sends those two
* items through the Selector function to create the result.
*
* One thing that's important to point out, is that Zip will throw away items
* that it can't use, similar to CombineLatest (i.e. if the left side is already
* full, it is replaced and the old one is lost). Unlike CombineLatest, Zip
* won't yield anything until it has a *new* thing on both sides.
*/
var leftSide = new[] {1,2,3,4}.ToObservable();
var rightSide = new[] { "A", "B", "C" }.ToObservable();
Observable.Zip(leftSide, rightSide, (num, letter) => num.ToString() + letter)
.Dump();