Operators conversion

The whole point with this category is to show how easy it is to create Observables from something so they can play nice with the operators and well whatever construct you come from enables rich composition.


In Rxjs4 there existed a bunch of operators with resembling names such as fromArray(), from(), fromPromise() etc. All these from() operators are now just from(). Let's look at some examples:

old fromArray

import { from } from 'rxjs';


old fromPromise

import { from } from 'rxjs';

from(new Promise(resolve, reject) => {
  // do async work
  resolve( data )


The of operator takes x number of arguments so you can call it with one arguments as well as 10 arguments like so:

import { of } from 'rxjs';



There also exist a bunch of operators that allows you go the other way, i.e leave the wonderful world of observables and go back to a more primitive state like :

import { of } from 'rxjs';

let promise = of(1,2).toPromise();
promise.then(data => console.log('Promise', data));

results matching ""

    No results matching ""