github.com/markusbkk/elvish@v0.0.0-20231204143114-91dc52438621/pkg/eval/vals/aliased_types.go (about)

     1  package vals
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/markusbkk/elvish/pkg/persistent/hashmap"
     7  	"github.com/markusbkk/elvish/pkg/persistent/vector"
     8  )
     9  
    10  // File is an alias for *os.File.
    11  type File = *os.File
    12  
    13  // List is an alias for the underlying type used for lists in Elvish.
    14  type List = vector.Vector
    15  
    16  // EmptyList is an empty list.
    17  var EmptyList = vector.Empty
    18  
    19  // MakeList creates a new List from values.
    20  func MakeList(vs ...interface{}) vector.Vector {
    21  	vec := vector.Empty
    22  	for _, v := range vs {
    23  		vec = vec.Conj(v)
    24  	}
    25  	return vec
    26  }
    27  
    28  // MakeListFromStrings creates a new List from strings.
    29  func MakeListFromStrings(ss ...string) vector.Vector {
    30  	vec := vector.Empty
    31  	for _, s := range ss {
    32  		vec = vec.Conj(s)
    33  	}
    34  	return vec
    35  }
    36  
    37  // Map is an alias for the underlying type used for maps in Elvish.
    38  type Map = hashmap.Map
    39  
    40  // EmptyMap is an empty map.
    41  var EmptyMap = hashmap.New(Equal, Hash)
    42  
    43  // MakeMap creates a map from arguments that are alternately keys and values. It
    44  // panics if the number of arguments is odd.
    45  func MakeMap(a ...interface{}) hashmap.Map {
    46  	if len(a)%2 == 1 {
    47  		panic("odd number of arguments to MakeMap")
    48  	}
    49  	m := EmptyMap
    50  	for i := 0; i < len(a); i += 2 {
    51  		m = m.Assoc(a[i], a[i+1])
    52  	}
    53  	return m
    54  }