u.go
2016-02-14T09:22:55Z

diff on groupBy and map in rxjs.js

|
| //
| //groupBy: <K, R>(keySelector: (value: T) => K, elementSelector?: (value: T) => R, durationSelector?: (group: GroupedObservable<K, R>) => Observable<any>) => Observable<GroupedObservable<K, R>>;
| //
| //map: <R>(project: (x: T, ix?: number) => R, thisArg?: any) => Observable<R>;
|
| var codes = [
| { keyCode: 38}, // up
| { keyCode: 38}, // up
| { keyCode: 40}, // down
| { keyCode: 40}, // down
| { keyCode: 37}, // left
| { keyCode: 39}, // right
| { keyCode: 37}, // left
| { keyCode: 39}, // right
| { keyCode: 66}, // b
| { keyCode: 38}, // up
| { keyCode: 38}, // up
| { keyCode: 65} // a
| ];
|
| //Observable.from(codes)
| // .map((x)=> x)
| // .subscribe(s => console.log(`next => ${s.keyCode}`))
|
|
| Observable.from(codes).groupBy(
| (x) => { return x.keyCode; },
| (x) => { return x; }
| ).subscribe(
| (obs) => {
| // Print the count
| obs.subscribe( (x) => {
| console.log('Count: ' + JSON.stringify(x));
| });
| },
| (err) => {
| console.log('Error: ' + err);
| },
| () => {
| console.log('Completed');
| });