Merge pull request #61 from Spriithy/feature/list_constructors

Added bulk constructors for arraylists & (doubly)-linked-lists
pull/88/head
Emir Pasic 7 years ago committed by GitHub
commit cbce439b4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -37,6 +37,13 @@ func New() *List {
return &List{} return &List{}
} }
// Of instantiates a new list of the given values
func Of(values ...interface{}) *List {
list := New()
list.Add(values)
return list
}
// Add appends a value at the end of the list // Add appends a value at the end of the list
func (list *List) Add(values ...interface{}) { func (list *List) Add(values ...interface{}) {
list.growBy(len(values)) list.growBy(len(values))

@ -39,6 +39,13 @@ func New() *List {
return &List{} return &List{}
} }
// Of instantiates a new list of the given values
func Of(values ...interface{}) *List {
list := New()
list.Add(values)
return list
}
// Add appends a value (one or more) at the end of the list (same as Append()) // Add appends a value (one or more) at the end of the list (same as Append())
func (list *List) Add(values ...interface{}) { func (list *List) Add(values ...interface{}) {
for _, value := range values { for _, value := range values {

@ -38,6 +38,13 @@ func New() *List {
return &List{} return &List{}
} }
// Of instantiates a new list of the given values
func Of(values ...interface{}) *List {
list := New()
list.Add(values)
return list
}
// Add appends a value (one or more) at the end of the list (same as Append()) // Add appends a value (one or more) at the end of the list (same as Append())
func (list *List) Add(values ...interface{}) { func (list *List) Add(values ...interface{}) {
for _, value := range values { for _, value := range values {

Loading…
Cancel
Save