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

flatmap using an array #707

@laurencefass

Description

@laurencefass

i'm trying to wrap my head around around flatmaps. In the array example at https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/selectmany.md what is y and where does it come from?

/* Using an array */
var source = Rx.Observable.of(1,2,3)
.flatMap(
function (x, i) { return [x,i]; },
function (x, y, ix, iy) { return x + y + ix + iy; }
);

note i changed the output of the original code to ease understanding of the pushed data. my subscription callback looks like this now.

var subscription = source.subscribe(
function (x) {
trace('Next: x = ' + x.x + " y = " + x.y + " ix = " + x.ix + " iy = " + x.iy);
},
function (err) {
trace('Error: ' + err);
},
function () {
trace('Completed');
}
);

my result like this:

Next: x = 1 y = 1 ix = 0 iy = 0
Next: x = 1 y = 0 ix = 0 iy = 1
Next: x = 2 y = 2 ix = 1 iy = 0
Next: x = 2 y = 1 ix = 1 iy = 1
Next: x = 3 y = 3 ix = 2 iy = 0
Next: x = 3 y = 2 ix = 2 iy = 1

a plain english explanation of the result, and an explanation of the derivation of y would be very useful. Thank you, Laurence

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions