Records and Tuples are an upcoming feature for Javascript, which may be familiar if you have used other languages. They are very similar to Arrays ...
For further actions, you may consider blocking this person and/or reporting abuse
[drops 🎤]
You solved Javascript
This is great news, but I wonder if there's a reason why we can't have something like this instead of the "#" thing
You can use Record() and Tuple() afaik if you have that preference
Yes, I understood it, I just think it would be more elegant and clear.
Here's my message on the thread discussing this proposal:
twitter.com/opensas/status/1499729...
The most obvious reason is to be able to pass records and tuples directly to functions as literals. Thus, in order to let the engine know how to handle such data, it needs its own syntax. Just another variable keyword doesn't cover this in future very common use case.
Good post. Given the mutation operations on records and tuples are common way to simulate immutable behavior now hopefully the transition will be as simple adding # sign in certain cases.
It would be interesting to see the performance differences between the generation of new object using spread vs generating new record using spread and likewise with tuples.
Based on your first example of a record nested in record, it seems that there would be benefit to having a "deep record" symbol to implicitly make nested arrays or objects also become records or tuples.
This looks great but I wonder the reasoning behind this. We can still achieve this using
Object.freeze
, so what is the benefit? Only thing I can see is compare by value but that does not seem that big of a reason to create new datatypes in a language. One thing I can think would help though is using Set/ Map with these. You can store complex record and to fetch it, all you need isset.get(#{...})
.Object.freeze isn't deeply immutable. From the MDN docs:
"The result of calling Object.freeze(object) only applies to the immediate properties of object itself and will prevent future property addition, removal or value re-assignment operations only on object. If the value of those properties are objects themselves, those objects are not frozen and may be the target of property addition, removal or value re-assignment operations."
The talk ”Solving Problems the Clojure Way”, by Rafal Dittwald is also relevant here since he is using JavaScript like if the objects and arrays were immutable in the example: youtube.com/watch?v=vK1DazRK_a0
This is great news! Anyone who wants to understand just how great should watch Rich Hickey's talk ”The Value of Values”: youtube.com/watch?v=-I-VpPMzG7c
Great post @smpnjn can you do a spread of a normal object in a record? same for arrays?