-
Notifications
You must be signed in to change notification settings - Fork 3
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
How will flatMap
handle undefined
returns?
#17
Comments
It throws if the mapper returns any non-iterator/iterable value, including You can try it today in Chrome 122+: |
(For async helpers, it will |
It's unfortunate that mapper returning a string will error out, i.e. that flatmap works on almost all iterables but not all of them |
I would consider that an intentional design decision; it's very harmful that strings are directly iterable and in new APIs we're generally requiring the iterable to be an object specifically to exclude strings. |
That's very much intentional. See discussion in tc39/proposal-iterator-helpers#244, tc39/proposal-iterator-helpers#229, etc. Wanting to treat a string as iterable for purposes of In any case, that's off-topic for this issue. |
Oh I'm sure it's intentional, yeah. I understand why too. Sorry, I swear I'm not trying to stir up controversy everywhere I go today. |
I'm a little fuzzy on how this (or iterator helpers) will handle
undefined
returns.Array#flatMap
will just add anundefined
value to the output flattened array. I assume the same is true here?The text was updated successfully, but these errors were encountered: