denis090712
02/13/2023, 11:02 AMfun <K, V> SortedMap<K, V>.take(count: Int): SortedMap<K, V> {
if (size <= count) return this
val found = keys.elementAt(count)
return headMap(found)
}
also, it is possible to implement drop
function in the same fashion
My case was to take a snapshot of the original tree of depth N.spand
02/13/2023, 11:51 AMSortedMap
in kotlinjw
02/13/2023, 1:13 PMspand
02/13/2023, 1:18 PMtake
and drop
on a jvm type when they arent present on Map
Marcin Wisniowski
02/20/2023, 11:20 AMMap
because the concept of taking the first 5 elements doesn’t make sense on an unordered map. It makes sense on SortedMap
, so it’s a valid request.spand
02/20/2023, 11:25 AMMap
is no more unordered than a Collection
or Set
or Iterable
which does have a take
method.Marcin Wisniowski
02/20/2023, 11:27 AM