Priya
02/09/2022, 8:36 PMOrderedSet (not sorted) in Kotlin? Any alternatives?ephemient
02/09/2022, 8:37 PMsetOf(), mutableSetOf(), mapOf(), mutableMapOf(), and returns of most methods such as .toSet(), .toMap(), etc. are documented to preserve insertion orderPriya
02/09/2022, 8:39 PMtakeLast(N) the last N items in a set without using reversed().take(N) ? Sets doesn’t seem to support takeLastephemient
02/09/2022, 8:40 PMPriya
02/09/2022, 8:44 PMmutableSetOf(1,2,3,1).reversed().take(3).reversed()ephemient
02/09/2022, 8:45 PM.toList().takeLast(N)ephemient
02/09/2022, 8:45 PMPriya
02/09/2022, 8:46 PMephemient
02/09/2022, 8:51 PMval lastN = ArrayDeque<T>(N)
for (item in items) {
if (lastN.size == n) lastN.removeFirst()
lastN.addLast(item)
}Priya
02/09/2022, 8:54 PMPaul Griffith
02/09/2022, 9:01 PM