src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/eval/vals/aliased_types.go (about) 1 package vals 2 3 import ( 4 "os" 5 6 "src.elv.sh/pkg/persistent/hashmap" 7 "src.elv.sh/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 ...any) vector.Vector { 21 return MakeListSlice(vs) 22 } 23 24 // MakeListSlice creates a new List from a slice. 25 func MakeListSlice[T any](vs []T) vector.Vector { 26 vec := vector.Empty 27 for _, v := range vs { 28 vec = vec.Conj(v) 29 } 30 return vec 31 } 32 33 // Map is an alias for the underlying type used for maps in Elvish. 34 type Map = hashmap.Map 35 36 // EmptyMap is an empty map. 37 var EmptyMap = hashmap.New(Equal, Hash) 38 39 // MakeMap creates a map from arguments that are alternately keys and values. It 40 // panics if the number of arguments is odd. 41 func MakeMap(a ...any) hashmap.Map { 42 if len(a)%2 == 1 { 43 panic("odd number of arguments to MakeMap") 44 } 45 m := EmptyMap 46 for i := 0; i < len(a); i += 2 { 47 m = m.Assoc(a[i], a[i+1]) 48 } 49 return m 50 }