Skip to content

Instantly share code, notes, and snippets.

@feliperohdee
Created July 7, 2016 16:35
Show Gist options
  • Save feliperohdee/1394540d27d200bb4f125034e05793ac to your computer and use it in GitHub Desktop.
Save feliperohdee/1394540d27d200bb4f125034e05793ac to your computer and use it in GitHub Desktop.
import {Observable, Subscriber} from 'rxjs';
class RX {
fromArray(array: Array<T>): Observable<Array<T>> {
return Observable.create((subscriber: Subscriber<Array<T>>) => {
try{
array.forEach((value: T, index: number) => subscriber.next(value));
}catch(e){
subscriber.error(e);
}
subscriber.complete();
});
}
}
let rx = new RX();
rx.fromArray([1,2,3,4])
.concatMap(item => Observable.of(item * 2).delay(500))
.subscribe(value => console.log(value));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment