artem_zin
08/04/2016, 1:46 PMplus()
on map, but can’t minus()
?
Basically I have immutable map and I need to remove item from it and get new immutable map as result.kittinunf
08/04/2016, 1:47 PMthomasnield
08/04/2016, 1:52 PMilya.gorbunov
08/04/2016, 2:48 PMMap.minus
operation? Should it take a key as an argument or a key-value pair like Map.plus
do?artem_zin
08/04/2016, 2:50 PMMap.plus()
has?ilya.gorbunov
08/04/2016, 2:52 PMminus
with a code example?artem_zin
08/04/2016, 2:57 PMvar map = mapOf(“s” to 1)
map -= “s"
Valid variants:
* minus(key)
* minus(Iterable<Key>)
Looks like there is no much sense in giving api to remove by key value pair, only key matters for minus
.ilya.gorbunov
08/04/2016, 2:59 PMminus
is not symmetrical with plus
, i.e. takes a key, whereas plus
takes a pair, so we decided not to provide them. We may reconsider that decision.artem_zin
08/04/2016, 3:02 PMremove(key)
because it returns removed value and not the new map. I see two ways at the moment: filter
(which is slow obviously) or create new mutable map with content of previous, remove item from it, then make it readonly.ilya.gorbunov
08/04/2016, 3:04 PMMutableMap
you can do just map.keys -= key
, but for read-only maps there is no easy way for now.jw
08/04/2016, 3:05 PMjw
08/04/2016, 3:06 PMfilter
might be faster than your second suggestion since the entries can be re-used instead of copiedthomasnield
08/04/2016, 3:07 PMilya.gorbunov
08/04/2016, 3:08 PMImmutableMap.remove(key)
member function which returns new ImmutableMap
instancejw
08/04/2016, 3:09 PMartem_zin
08/04/2016, 3:11 PMthomasnield
08/04/2016, 3:16 PMgroupBy()
kind of does that already. As long as groupBy()
has some form of ImmutableList
equivalent I'll be cool with that.thomasnield
08/04/2016, 3:17 PMSequence
?ilya.gorbunov
08/04/2016, 3:17 PMgroupBy
returns read-only map of read-only lists. Is read-only sufficient, or do you need immutability?thomasnield
08/04/2016, 3:19 PMvoddan
08/04/2016, 3:21 PMI don't need immutability, but I like it. I understand it performs betterusually it does not
thomasnield
08/04/2016, 3:24 PMImmutableList
boasted some pretty sizable performance over ArrayList
.ilya.gorbunov
08/04/2016, 3:31 PMartem_zin
08/04/2016, 3:31 PMmap.minus(key)
and map.minus(keys)
deserve to live in stdlib?ilya.gorbunov
08/04/2016, 3:32 PMartem_zin
08/04/2016, 3:34 PMilya.gorbunov
08/04/2016, 3:36 PMartem_zin
08/04/2016, 3:42 PMrocketraman
08/04/2016, 7:25 PMfun <T> List<T>.replace(index: Int, new: T): List<T>
function. Should one exist in stdlib?