Created
February 14, 2016 09:22
-
-
Save maowug/4115b7395711035e4ac7 to your computer and use it in GitHub Desktop.
diff on groupBy and map in rxjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
//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'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment