Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Latest commit

 

History

History
95 lines (77 loc) · 2.68 KB

pairs.md

File metadata and controls

95 lines (77 loc) · 2.68 KB

Rx.Observable.pairs(obj, [scheduler])

Convert an object into an observable sequence of [key, value] pairs using an optional Scheduler to enumerate the object.

Arguments

  1. obj (Object): The object to inspect and turn into an Observable sequence.
  2. [scheduler] (Scheduler): Scheduler to run the enumeration of the input sequence on. If not specified, defaults to Rx.Scheduler.currentThread

Returns

(Observable): An observable sequence of [key, value] pairs from the object.

Example

// Using Standard JavaScript
var obj = {
  foo: 42,
  bar: 56,
  baz: 78
};

var source = Rx.Observable.pairs(obj);

var subscription = source.subscribe(
  function (x) {
    console.log('Next: %s', x);
  },
  function (err) {
    console.log('Error: %s', err);
  },
  function () {
    console.log('Completed');
  });

// => Next: ['foo', 42]
// => Next: ['bar', 56]
// => Next: ['baz', 78]
// => Completed

ES6 makes for an even nicer experience such as:

let obj = {
  foo: 42,
  bar: 56,
  baz: 78
};

let source = Rx.Observable.pairs(obj);

let subscription = source.subscribe(
  x => {
    var [key, value] = x;
    console.log('Key:', key, 'Value:', value);
  },
  err => {
    console.log('Error: %s', err);
  },
  => () {
    console.log('Completed');
  });

// => Key: 'foo' Value: 42
// => Key: 'bar' Value: 56
// => Key: 'baz' Value: 78
// => Completed

Location

File:

Dist:

Prerequisites:

  • None

NPM Packages:

NuGet Packages:

Unit Tests: