Hullaballoonatic
11/29/2019, 5:57 PMfun <K, V> Array<K>.associateWith(valueSelector: (K) -> V): Map<K, V>
why is this not in stdlib already? i'm very confused.
all other versions of associate from Iterable exist on Array except this one.
my use case:
myEnumClass.values().associateWith { ... }ilya.gorbunov
11/29/2019, 6:00 PMasList() on the array.Hullaballoonatic
11/29/2019, 6:01 PMasList have significant overhead?Hullaballoonatic
11/29/2019, 6:02 PMArray doesn't have this method like one would expect, doesn't it beg the question "why did this person cast this array to list?" whenever you perform the operation this way?Hullaballoonatic
11/29/2019, 6:02 PMfun <K, V> Array<K>.associateWith(valueSelector: (K) -> V): Map<K, V> = associate { it to valueSelector(it) }ilya.gorbunov
11/29/2019, 6:03 PMdoesNo, far less overhead than turning each item into a pairhave significant overhead?asList
Hullaballoonatic
11/29/2019, 6:04 PMHullaballoonatic
11/29/2019, 6:05 PMfun <K, V> Array<K>.associateWith(valueSelector: (K) -> V): Map<K, V> = asList().associateWith(valueSelector)ilya.gorbunov
11/29/2019, 6:13 PMBurkhard
11/29/2019, 6:46 PMdoesOne easy way to see that it doesn’t is to remember the difference ofhave significant overhead?asList
asXXX and toXXX in the stdlib. asXXX always creates a wrapper which normally has a minimal overhead. toXXX on the other hand creates a copy.miha-x64
11/30/2019, 7:25 AM