list-type.go: two special constructors, MakeList() and ListFromStrigns(), added
This commit is contained in:
parent
08e0979cdd
commit
00c76b41f1
21
list-type.go
21
list-type.go
@ -20,6 +20,10 @@ func newListA(listAny ...any) (list *ListType) {
|
||||
}
|
||||
|
||||
func newList(listAny []any) (list *ListType) {
|
||||
return NewList(listAny)
|
||||
}
|
||||
|
||||
func NewList(listAny []any) (list *ListType) {
|
||||
if listAny != nil {
|
||||
ls := make(ListType, len(listAny))
|
||||
for i, item := range listAny {
|
||||
@ -30,6 +34,23 @@ func newList(listAny []any) (list *ListType) {
|
||||
return
|
||||
}
|
||||
|
||||
func MakeList(length, capacity int) (list *ListType) {
|
||||
if capacity < length {
|
||||
capacity = length
|
||||
}
|
||||
ls := make(ListType, length, capacity)
|
||||
list = &ls
|
||||
return
|
||||
}
|
||||
|
||||
func ListFromStrings(stringList []string) (list *ListType) {
|
||||
list = MakeList(len(stringList), 0)
|
||||
for i, s := range stringList {
|
||||
(*list)[i] = s
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (ls *ListType) ToString(opt FmtOpt) (s string) {
|
||||
var sb strings.Builder
|
||||
sb.WriteByte('[')
|
||||
|
Loading…
Reference in New Issue
Block a user