github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/slice/group/api.go (about)

     1  // Package group provides short aliases for grouping functions
     2  package group
     3  
     4  import (
     5  	"github.com/m4gshm/gollections/slice"
     6  )
     7  
     8  // Of is a short alias for slice.Group
     9  func Of[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) map[K][]V {
    10  	return slice.Group(elements, keyExtractor, valExtractor)
    11  }
    12  
    13  // ByMultiple is a short alias for slice.GroupByMultiple
    14  func ByMultiple[TS ~[]T, T any, K comparable, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) map[K][]V {
    15  	return slice.GroupByMultiple(elements, keysExtractor, valsExtractor)
    16  }
    17  
    18  // ByMultipleKeys is a short alias for slice.GroupByMultipleKeys
    19  func ByMultipleKeys[TS ~[]T, T any, K comparable, V any](elements TS, keysExtractor func(T) []K, valExtractor func(T) V) map[K][]V {
    20  	return slice.GroupByMultipleKeys(elements, keysExtractor, valExtractor)
    21  }
    22  
    23  // ByMultipleValues is a short alias for slice.GroupByMultipleVals
    24  func ByMultipleValues[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valsExtractor func(T) []V) map[K][]V {
    25  	return slice.GroupByMultipleValues(elements, keyExtractor, valsExtractor)
    26  }