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

Why is Record.fromEntries restricted to an iterable of tuples? #102

Closed
dead-claudia opened this issue Mar 6, 2020 · 3 comments · Fixed by #103
Closed

Why is Record.fromEntries restricted to an iterable of tuples? #102

dead-claudia opened this issue Mar 6, 2020 · 3 comments · Fixed by #103

Comments

@dead-claudia
Copy link
Contributor

Record.fromEntries is explicitly restricted to only coercing from 2-tuples of values. This is inconsistent with basically every other native type, which accept iterables of iterables, and it only takes the first 2 values of the inner iterable. Also, for the purposes of this, the inner pairs don't really need to be immutable, as you'd need to pull the keys and values out anyways because the key needs coerced to a string and because engines aren't going to want to store it as a list of literal key/value pairs directly - it's only efficient to iterate.

@ljharb
Copy link
Member

ljharb commented Mar 6, 2020

Which native type accepts an iterable of iterables? Map and WeakMap accept an iterable of "arraylikes of length 2", and throw if it's something else; Set and WeakSet accept an iterable of values…

@dead-claudia
Copy link
Contributor Author

Oh, okay. Didn't remember that specific with maps, weak maps, and Object.fromEntries. (I'm referring to those specifically.) But still, the restriction with Record.fromEntries seems arbitrary.

@rickbutton
Copy link
Member

Record.fromEntries should take an iterable of 2-element array-like values, just like Object.fromEntries, I agree.

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

Successfully merging a pull request may close this issue.

3 participants