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

     1  // Package map_ provides immutale ordered.Map constructors
     2  package map_
     3  
     4  import (
     5  	"github.com/m4gshm/gollections/c"
     6  	"github.com/m4gshm/gollections/collection/immutable/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  // New instantiates a map and copies the elements to it
    15  func New[K comparable, V any](elements map[K]V, order []K) ordered.Map[K, V] {
    16  	return ordered.NewMapOf(order, elements)
    17  }
    18  
    19  // From instantiates a map with key/values retrieved by the 'next' function.
    20  // The next returns a key/value pairs with true or zero values with false if there are no more elements.
    21  func From[K comparable, V any](next func() (K, V, bool)) ordered.Map[K, V] {
    22  	return ordered.MapFromLoop(next)
    23  }