Files
lo/docs/data/it-partitionby.md
T
2025-10-06 17:16:33 +02:00

789 B

name, slug, sourceRef, category, subCategory, signatures, variantHelpers, similarHelpers, position
name slug sourceRef category subCategory signatures variantHelpers similarHelpers position
PartitionBy partitionby it/seq.go#L26 it sequence
func PartitionBy[T any, K comparable](collection iter.Seq[T], transform func(item T) K) [][]T
core#slice#partitionby
171

PartitionBy returns a sequence of elements split into groups. The order of grouped values is determined by the order they occur in collection. The grouping is generated from the results of running each element of collection through transform.

collection := func(yield func(int) bool) {
    yield(1)
    yield(2)
    yield(3)
    yield(4)
    yield(5)
    yield(6)
}

result := it.PartitionBy(collection, func(x int) int {
    return x % 3
})
// result contains [[1, 4], [2, 5], [3, 6]]