Skip to content

Instantly share code, notes, and snippets.

@olimungo
Created May 2, 2017 14:14
Show Gist options
  • Save olimungo/411b8e06c4054e7eb42c09568d769b7e to your computer and use it in GitHub Desktop.
Save olimungo/411b8e06c4054e7eb42c09568d769b7e to your computer and use it in GitHub Desktop.
import { Observable } from './node_modules/rxjs/Rx';
const list = [
{ id: 1, name: 'Oli', type: 0 },
{ id: 2, name: 'Pedro', type: 1 },
{ id: 3, name: 'Rui', type: 1 },
{ id: 4, name: 'Ainara', type: 2 }
];
const types = [
{ label: 'ALPHA' },
{ label: 'BETA' },
{ label: 'DELTA' }
];
list$()
.switchMap(list => Observable.from(list))
.concatMap(item => {
return type$(item.type)
.map(type => {
return { id: item.id, name: item.name, type: type.label };
});
})
.subscribe(res => console.log(res));
function list$(): Observable<any[]> {
return Observable.of(list);
}
function type$(id: number): Observable<any> {
return Observable.of(types[id]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment