0

Was just wondering if there an equivalent flatMap function in Immutable.js? I have been using this node package https://www.npmjs.com/package/flatmap for a while but I would prefer to write things like this

listObject.flatMap(x => ...)

Instead of

flatMap(listObject, x => ...)
foomip
  • 574
  • 7
  • 7
  • 1
    what about [List#flatMap](http://facebook.github.io/immutable-js/docs/#/List/flatMap) in Immutable.js? – Thomas Aug 30 '16 at 15:43
  • If I could I would mark you comment as the correct answer. Yep, for some reason I didn't find flatMap in the Immutable.js docs (not the easiest to use docs) but after looking again carefully I see the iterables have a flatMap function. – foomip Aug 31 '16 at 18:57
  • @foomip I updated my answer. However, I think it is a good idea to leave my old answer too, just for future users who are facing the same problem. –  Aug 31 '16 at 19:05

1 Answers1

2

Actually, there is a flatMap function (see documentation).

However, if you ever face a similar problem (you want to use foo.bar(args) instead of bar(foo, args)) you can create a custom property of your instance.

listObject.flatMap = a => flatMap(listObject, a);

And after that it is equivalent to write flatMap(listObject, x => ...) and listObject.flatMap(x => ...).