Back to Lo

It Groupby

docs/data/it-groupby.md

1.53.0552 B
Original Source

Returns an object composed of keys generated from running each element of collection through a transform function. The value of each key is an array of elements responsible for generating the key.

Examples:

go
seq := func(yield func(string) bool) {
    _ = yield("apple")
    _ = yield("banana")
    _ = yield("apricot")
    _ = yield("blueberry")
}
grouped := it.GroupBy(seq, func(s string) string {
    return string(s[0]) // group by first letter
})
// grouped contains map with keys: "a": ["apple", "apricot"], "b": ["banana", "blueberry"]