I've adjusted my implementations for Object.fromEn...
# javascript
b
I've adjusted my implementations for Object.fromEntries: what is the purpose of returning ReadonlyRecord instead of record? technically speaking, there's nothing that would prohibit you from modifying the newly constructed JS object again. In the Kotlin std lib, the default implementations are immutable, so you get a covariant list by default. So I think we should return a Record instead from fromEntries or provide a fromEntriesMutable version
t
or add
copy
method for transformation?
Could you share your use case?
b
sorry, was in a game 🙂
let me look up copy
ok, does not seem like one is available/generated for records
in general I think copying wouldn't be a huge performance hit since you're just copying pointers
as for my use case: function/method signature compatibility mostly
imagine having methods that work on mutable records and now you want to pass in a non mutable one
if it's doable in an easy fashion, you can just adjust the signatures across the board, otherwise you probably want to cast to a mutable one since there's basically no difference
now Object.freeze, that would make a difference
at least for fromEntries, I think there should be to ways that you can choose from, similar to sequence.toList() vs sequence.toMutableList()
and ideally, immutability is ensured by using Object.freeze on the readonly one
at least the current situation neither translates to what you'd expect from that JS method (every object is mutable by default) nor are there parallels to how the kotlin stdlib does things
either way, I don't have hard feelings about how it'll be implemented eventually but it might make sense to make it behave close to the JS or Kotlin stdlib defaults
t
imagine having methods that work on mutable records
Please no 🙂
For me it’s like methods, which receive
MutableList
as parameter - it doesn’t look like Kotlin way
b
I guess the solution then is to go for something similar to copy
the JS APIs kinda got me back into JS brain
just realized we had anonymous objects as well in Kotlin this evening