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

     1  // Package group provides short aliases for functions that are used to group collection elements
     2  package group
     3  
     4  import (
     5  	"github.com/m4gshm/gollections/c"
     6  	"github.com/m4gshm/gollections/slice"
     7  )
     8  
     9  // Of converts the 'elements' slice of key\value pairs.
    10  func Of[TS ~[]c.KV[K, V], K comparable, V any](elements TS) map[K][]V {
    11  	if elements == nil {
    12  		return nil
    13  	}
    14  	return slice.Group(elements, c.KV[K, V].Key, c.KV[K, V].Value)
    15  }