Comments (5)
I think this is a duplicate of #375
Applying the construction recursively could slow down creating the values, as the original mutable object would be created and then the 2nd record/tuple gets created. Having explicit syntax at the construction site makes this easier to avoid.
For an example like:
#{ p: [2,4] }
It looks like it is easy to optimise out the creation of the array and infer that the inner value should be a tuple but with indirection it becomes harder:
const getArr = () => [2,4];
#{ p: getArr() };
More analysis is required to optimise out the array. This could lead to surprising performance differences between very similar code.
It may also result in errors, when invalid values are used; being thrown later due to the delay in converting the array/object to a tuple/record. Making it harder to spot the source of the invalid value.
from proposal-record-tuple.
Sure. But it will make the code reading more clear, which is always more important than how hard it is to write.
from proposal-record-tuple.
Why would there never be such a situation, where someone attempts or intends to do that?
from proposal-record-tuple.
I think that if recursive creation is not supported, it will not prevent people from trying to create nested Record/Tuple, but it will just make the code writing more cumbersome:
const getArr = () => [2,4];
#{ p: #[...getArr()] };
from proposal-record-tuple.
Since it is deeply immutable, nested data must be converted to immutable. I don't think the more cumbersome way of writing it would make the code clearer to read.
Also I wish this syntactic sugar could be used for any expression, not just object/array literals.
I actually thought it would be more convenient to use #
at the end of the expression:
const [head, ...rest] = [1,2,3]#
console.log(rest# === [2,3]#)
console.log(someObj.getSomeValue()# === targetTuple)
from proposal-record-tuple.
Related Issues (20)
- Record keys are deduplicated, but should duplicates generate a thrown error? HOT 5
- brad4d Stage 3 Review feedback HOT 9
- Forbid hosts creating an impossible records/tuples
- Can we agree on a list of design goals for the README? HOT 2
- Upgradeable ArrayBuffers HOT 5
- add support for tuples to {Async,}Iterator.prototype.flatMap and {Async,}Iterator.from
- `Record` name conflict with Typescript HOT 1
- Why mixing immutability and tuples ? HOT 5
- `let` binding record and tuple should be writable HOT 6
- Some syntactic sugar: no need to insert # before every nested structure HOT 4
- Is this planned for ES14? HOT 6
- What about sets? HOT 14
- Can I use? HOT 12
- Is empty tuple / record falsy? HOT 8
- Syntax problems with VSCode HOT 2
- Does `.with()` accept array as first argument? HOT 1
- Map/Set’s SameValueZero key/value mapping HOT 2
- Looking to confirm: CanBeHeldWeakly remains false even if rec/tup includes unforgeable symbols? HOT 2
- Tuple.fromAsync?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-record-tuple.