github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/collection/immutable/map_/api.go (about) 1 // Package map_ provides immutable.Map constructors 2 package map_ //nilint 3 4 import ( 5 "github.com/m4gshm/gollections/c" 6 "github.com/m4gshm/gollections/collection/immutable" 7 "github.com/m4gshm/gollections/kv/loop" 8 ) 9 10 // Of instantiates a ap from the specified key/value pairs 11 func Of[K comparable, V any](elements ...c.KV[K, V]) immutable.Map[K, V] { 12 return immutable.NewMap(elements...) 13 } 14 15 // New instantiates Map and copies elements to it 16 func New[K comparable, V any](elements map[K]V) immutable.Map[K, V] { 17 return immutable.NewMapOf(elements) 18 } 19 20 // From instantiates a map with key/values retrieved by the 'next' function. 21 // The next returns a key/value pairs with true or zero values with false if there are no more elements. 22 func From[K comparable, V any](next func() (K, V, bool)) immutable.Map[K, V] { 23 return immutable.WrapMap(loop.ToMap(next)) 24 }