diff --git a/lists/arraylist/arraylist.go b/lists/arraylist/arraylist.go index e0919eb..34eeb4e 100644 --- a/lists/arraylist/arraylist.go +++ b/lists/arraylist/arraylist.go @@ -37,6 +37,13 @@ func New() *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 func (list *List) Add(values ...interface{}) { list.growBy(len(values)) diff --git a/lists/doublylinkedlist/doublylinkedlist.go b/lists/doublylinkedlist/doublylinkedlist.go index 97ddbad..5daf5eb 100644 --- a/lists/doublylinkedlist/doublylinkedlist.go +++ b/lists/doublylinkedlist/doublylinkedlist.go @@ -39,6 +39,13 @@ func New() *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()) func (list *List) Add(values ...interface{}) { for _, value := range values { diff --git a/lists/singlylinkedlist/singlylinkedlist.go b/lists/singlylinkedlist/singlylinkedlist.go index 95eabd3..86e58a9 100644 --- a/lists/singlylinkedlist/singlylinkedlist.go +++ b/lists/singlylinkedlist/singlylinkedlist.go @@ -38,6 +38,13 @@ func New() *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()) func (list *List) Add(values ...interface{}) { for _, value := range values {