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

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