andylamax
09/18/2022, 2:22 AMCollection and MutableCollection interfaces
⢠The List and MutableList interfaces
⢠The Set and MutableSet interfaces
⢠The Map and MutableMap interfaces
1. The collections are not marked with @JsExport making their consumption from JS/TS extremely difficult
2. There is no easy way to convert an instance of either of these collections to their native collection counterpart data structures (List -> Array,Set,Map)
We are currently wrapping these Collections to make them easy to use, but it feels inconvenient to have yet another wrapping of these basic building blocks of almost any library/application. We have expect/actuals in place so that we only do the wrapping in JS targets but that does require different builders to construct the said collections. This is very confusing especially for people joining the team
We tried using Array in favor of List but they don't play well as properties for data classes.
I know the team is currently focused on the compiler right now, but I would like to shed light one more time on how little things like these are also a crucial part of a language (at least its standard library).ephemient
09/18/2022, 4:51 AMList / JS Array interop: how? custom List implementations, e.g.
object AlmostInfiniteList : AbstractList<String>() {
override val size get() = Int.MAX_VALUE
override fun get(index: Int) = index.toString()
}
can't be JS `Array`sephemient
09/18/2022, 4:53 AMSet is ES6 and Kotlin doesn't target ES6 yetephemient
09/18/2022, 4:55 AMMap is ES6 and isn't commonly usedephemient
09/18/2022, 4:57 AMandylamax
09/18/2022, 6:53 AMandylamax
09/18/2022, 6:54 AMephemient
09/18/2022, 7:07 AMregisterOnce(sameInstanceOfArray) twice, where the function is implemented in Kotlin, and Kotlin is transparently wrapping that to List, do you expect to receive the same instance twice? ditto the other way around. I don't see how that can work in generalturansky
09/18/2022, 12:33 PMandylamax
09/18/2022, 2:34 PMandylamax
09/18/2022, 2:40 PMturansky
09/18/2022, 3:30 PMWhich are almost impossible to consume from JSIt looks like expected behaviour from my side
turansky
09/18/2022, 3:31 PMankushg
11/29/2022, 8:36 PMMap <> JsMap and Set <> JsSet for things that are annotated with @JsExport
Almost similar to the KMP-NativeCoroutines project that generates helpers for `suspend fun`s for iOSturansky
11/29/2022, 10:11 PMX to any Y , because Map and JsMap have common name, but different behaviour.
Just for start:
Map - interface
JsMap - class
Map can have different implementations.
JsMap also can have multiple child types.
Map contract - use equal for key comparing
JsMap contract - use === for key comparing
You can create class SuperMap: JsMap, Map and replace all mapOf() and emptyMap() calls but it will help only in situation, when Map used as output type.
How to find all possible âinput casesâ? Is it possible?andylamax
11/30/2022, 12:23 AM@JsExport was meant to help solve this, but it fails miserably coz those collection interfaces are not even exported from the stdlib themselvesturansky
11/30/2022, 11:37 AMMake these kotlin.collection consumable from JS (something that is very possible to do, but currently not being done)From my side it doesnât look like âvery possibleâ. Itâs definitely problem, for which I donât see simple common solution.
Map , List , Set , Comparable , Sequence , Comparator , Iterator , Iterable have no native analogs, which have String , Array , Boolean.andylamax
11/30/2022, 12:47 PMturansky
11/30/2022, 1:33 PMSo, for it to be usable, it doesnât need to be converted into a native analogFor me itâs open question
andylamax
11/30/2022, 9:17 PM@JsExport and given a .toArray() method which makes it easy to break from the Kotlin world to the JS world. (We currently have a wrapper that does this)andylamax
11/30/2022, 9:19 PMSet and Map can share the same fate. All marked with @JsExport and be given a .toJsSet and a .toJsMap method respectively