https://kotlinlang.org logo
#stdlib
Title
# stdlib
d

Dias

12/06/2018, 11:17 PM
Is there a standard function that would split collection into buckets depending on some parameter?
s

Shawn

12/06/2018, 11:17 PM
sounds kinda like you want
.groupBy { ... }
going to have to be more specific on what you mean by “buckets” and “depending on some parameter”
p

pavel

12/06/2018, 11:19 PM
there is also
.partition{...}
for simpler cases
s

Shawn

12/06/2018, 11:19 PM
correct, if you have a boolean predicate, partition might be a better choice
d

Dias

12/06/2018, 11:20 PM
yeah something like partition but without predefined number of partitions
I guess groupby will work for me, if I then strip the keys
s

Shawn

12/06/2018, 11:21 PM
you can call
.values
on the resulting map to get a collection containing your “buckets”
d

Dias

12/06/2018, 11:22 PM
yeah, I should have thought about groupBy, thank you
👍 2
h

hmole

12/07/2018, 6:59 AM
Sequence<T>.chunked()
s

Shawn

12/07/2018, 1:25 PM
@hmole sure, if “some parameter” is just the number of elements you want in each resulting list
the request was vague enough that I figured they wanted just arbitrary criterion support