Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flatMap not working #263

Open
ghost opened this issue Nov 8, 2018 · 2 comments
Open

flatMap not working #263

ghost opened this issue Nov 8, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Nov 8, 2018

I tried this example in the docs and the returned array isn't changed at all

var array = Immutable(["drop the numbers!", 3, 2, 1, 0, null, undefined]);
Immutable.flatMap(array, function(value) {
  if (typeof value === "number") {
    return [];
  } else {
    return value;
  }
});
// expected: ["drop the numbers!", null, undefined]
// reality: ["drop the numbers!", 3, 2, 1, 0, null, undefined]

I'm using seamless-immutable v7.1.4. Is this a bug or am I doing anything wrong?

@crudh
Copy link
Collaborator

crudh commented Jan 5, 2019

@lightnguyen not sure, but I added this test case and it seems to work as expected?

    it("filters out things as expected when returning empty array", function() {
      var array = Immutable(["drop the numbers!", 3, 2, 1, 0, null, undefined]);
      var expected = Immutable(["drop the numbers!", null, undefined]);
      var actual = Immutable.flatMap(array, function(value) {
        if (typeof value === "number") {
          return [];
        } else {
          return value;
        }
      });

      TestUtils.assertJsonEqual(actual, expected);
    });

@Liaozhenting
Copy link

Looks like you expecte immutable variable 'array' is ["drop the numbers!", 3, 2, 1, 0, null, undefined]. This is not right. You need a another variable to take the return of Immutable.flatMap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants