github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/collection/mutable/map_/api.go (about)

     1  // Package map_ provides unordered mutable.Map constructors
     2  package map_
     3  
     4  import (
     5  	"github.com/m4gshm/gollections/c"
     6  	"github.com/m4gshm/gollections/collection/mutable"
     7  )
     8  
     9  // Of instantiates a ap from the specified key/value pairs
    10  func Of[K comparable, V any](elements ...c.KV[K, V]) *mutable.Map[K, V] {
    11  	return mutable.NewMap(elements...)
    12  }
    13  
    14  // Empty instantiates a Map with zero capacity.
    15  func Empty[K comparable, V any]() *mutable.Map[K, V] {
    16  	return New[K, V](0)
    17  }
    18  
    19  // New instantiates a Map with a predefined capacity.
    20  func New[K comparable, V any](capacity int) *mutable.Map[K, V] {
    21  	return mutable.NewMapCap[K, V](capacity)
    22  }
    23  
    24  // From instantiates a map with elements obtained by passing the 'loop' function
    25  func From[K comparable, V any](next func() (K, V, bool)) *mutable.Map[K, V] {
    26  	return mutable.MapFromLoop(next)
    27  }