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

Add recursive conversion routines? #122

Closed
littledan opened this issue May 27, 2020 · 6 comments
Closed

Add recursive conversion routines? #122

littledan opened this issue May 27, 2020 · 6 comments

Comments

@littledan
Copy link
Member

Various people have raised the feature request that a recursive conversion routine should be built-in, to convert structures of Objects and Arrays to Records and Tuples. Lots of JS immutable data structure libraries have this capability.

The current draft proposal does not contain recursive conversion routines, though of course they can be implemented in JS. I think these are often used inappropriately (e.g., to clone, which should be unnecessary), and I'm not convinced we should encourage this pattern with a built-in function.

I'd be open to adding this, if we have good use cases. One option is that we could make a depth limit parameter, as the README suggests. I'm not sure if this would result in feeling too low-level, though (and people could always get around it by using a large value...).

cc @rauschma

@pabloalmunia
Copy link

Usually, the Javascript language only provide functions to superficial transformation, for example, Object.assign() only work into the first level and don't work recursively into next object levels.

A good recursive function should be to work with circular references and other complex situations. JSON.stringify () is the only function that works in depth and has serious problems with circular reference situations.

In my experience (I've developed a recursive immutability library https://www.todojs.com/datos-inmutables-en-javascript/ ) it's more idiomatic that maintained built-in functions are kept at the superficial level.

@papb
Copy link

papb commented May 27, 2020

I think this could be left to another proposal, if necessary. It might be safer to have this proposal land without this feature first, and then see how it goes, maybe?

@njordhov

This comment has been minimized.

@littledan

This comment has been minimized.

@njordhov
Copy link

njordhov commented Jun 8, 2020

@njordhov I've hidden your comment since this issue is about recursive conversion routines, not syntax. You've already been arguing for this syntax change on #10; no need to spread that conversation out over multiple issues.

The point is that having recursive conversion routines makes a cleaner record literal syntax comprehensible rather than confusing. This is an on-topic response to the request in OP, making a case in favor of adding recursive conversion. The original post is here, with only a brief mention added to #10 (before I had to answer to what seems like knee-jerk responses from the past syntax discussion).

@rricard
Copy link
Member

rricard commented Jul 8, 2022

In order to focus on changes that are necessary to finish this proposal, we are closing issues related to follow-on proposals. You are free to continue the discussion here and reference it in other venues.

@rricard rricard closed this as completed Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants