d

    Dias

    3 years ago
    Is there a standard function that would split collection into buckets depending on some parameter?
    Shawn

    Shawn

    3 years ago
    sounds kinda like you want
    .groupBy { ... }
    going to have to be more specific on what you mean by “buckets” and “depending on some parameter”
    pavel

    pavel

    3 years ago
    there is also
    .partition{...}
    for simpler cases
    Shawn

    Shawn

    3 years ago
    correct, if you have a boolean predicate, partition might be a better choice
    d

    Dias

    3 years ago
    yeah something like partition but without predefined number of partitions
    I guess groupby will work for me, if I then strip the keys
    Shawn

    Shawn

    3 years ago
    you can call
    .values
    on the resulting map to get a collection containing your “buckets”
    d

    Dias

    3 years ago
    yeah, I should have thought about groupBy, thank you
    h

    hmole

    3 years ago
    Sequence<T>.chunked()
    Shawn

    Shawn

    3 years ago
    @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