Stefan Peterson
03/05/2019, 6:32 PMid
. These `id`s are unique. I know I can use groupBy
to create a map but that results in Map<Long, List<*>>
when I would much rather have Map<Long, *>
. Is there a nice idiomatic way to do this in :kotlin:?Czar
03/05/2019, 6:51 PMlistOfObjects.mapTo(mutableListOf()) { it.id to it }.toMap()
listOfObjects.map { it.id to it }.toMap()
Stefan Peterson
03/05/2019, 8:56 PMassociateBy
which is actually the most optimal solution I think.Nikky
03/05/2019, 9:21 PMlist.associate { it.id to it }
associateBy is skipping the value part i think.. so i probably makes this even shortergildor
03/06/2019, 1:57 AMlist.associateBy { it.id }
Czar
03/06/2019, 9:40 AM