github.com/m4gshm/gollections@v0.0.10/collection/mutable/ordered/map_/api.go (about)

     1  // Package map_ provides mutable ordered.Map constructors
     2  package map_
     3  
     4  import (
     5  	"github.com/m4gshm/gollections/c"
     6  	"github.com/m4gshm/gollections/collection/mutable/ordered"
     7  )
     8  
     9  // Of instantiates a ap from the specified key/value pairs
    10  func Of[K comparable, V any](pairs ...c.KV[K, V]) *ordered.Map[K, V] {
    11  	return ordered.NewMap(pairs...)
    12  }
    13  
    14  // Empty instantiates a map with zero capacity
    15  func Empty[K comparable, V any]() *ordered.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) *ordered.Map[K, V] {
    21  	return ordered.WrapMap(make([]K, 0, capacity), make(map[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)) *ordered.Map[K, V] {
    26  	return ordered.MapFromLoop(next)
    27  }