Created
July 7, 2016 16:35
-
-
Save feliperohdee/1394540d27d200bb4f125034e05793ac to your computer and use it in GitHub Desktop.
This file contains 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
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