Skip to content

Latest commit

 

History

History
147 lines (101 loc) · 3.25 KB

File metadata and controls

147 lines (101 loc) · 3.25 KB

{% if book.isPdf %}

from

{% else %}

{% endif %}

This method creates a new Observable sequence from an array-like or iterable object.

Arguments

  1. iterable (Array | Arguments | Iterable): An array-like or iterable object to convert to an Observable sequence.
  2. [mapFn] (Function): Map function to call on every element of the array.
  3. [thisArg] (Any): The context to use calling the mapFn if provided.
  4. [scheduler=Rx.Scheduler.currentThread] (Scheduler): Scheduler to run the enumeration of the input sequence on.

Returns

(Observable): The observable sequence whose elements are pulled from the given iterable sequence.

Example

{% if book.isPdf %}

function f() {
  return Rx.Observable.from(arguments);
}

f(1, 2, 3).subscribe(
  x => console.log(`onNext: ${x}`),
  e => console.log(`onError: ${e}`),
  () => console.log('onCompleted'));

// => onNext: 1
// => onNext: 2
// => onNext: 3
// => onCompleted
var s = new Set(["foo", window]);

Rx.Observable.from(s).subscribe(
  x => console.log(`onNext: ${x}`),
  e => console.log(`onError: ${e}`),
  () => console.log('onCompleted'));

// => onNext: foo
// => onNext: window
// => onCompleted
var m = new Map([[1, 2], [2, 4], [4, 8]]);

Rx.Observable.from(m).subscribe(
  x => console.log(`onNext: ${x}`),
  e => console.log(`onError: ${e}`),
  () => console.log('onCompleted'));

// => onNext: [1, 2]
// => onNext: [2, 4]
// => onNext: [4, 8]
// => onCompleted
Rx.Observable.from("foo").subscribe(
  x => console.log(`onNext: ${x}`),
  e => console.log(`onError: ${e}`),
  () => console.log('onCompleted'));

// => onNext: f
// => onNext: o
// => onNext: o
// => onCompleted
Rx.Observable.from([1, 2, 3], x => x + x).subscribe(
  x => console.log(`onNext: ${x}`),
  e => console.log(`onError: ${e}`),
  () => console.log('onCompleted'));

// => onNext: 2
// => onNext: 4
// => onNext: 6
// => onCompleted
Rx.Observable.from({length: 5}, (v, k) => k).subscribe(
  x => console.log(`onNext: ${x}`),
  e => console.log(`onError: ${e}`),
  () => console.log('onCompleted'));

// => onNext: 0
// => onNext: 1
// => onNext: 2
// => onNext: 3
// => onNext: 4
// => onCompleted

{% else %}

Array-like object (arguments) to Observable

Set

Map

String

Array

Generate a sequence of numbers

{% endif %}