diff --git a/lists/arraylist/arraylist.go b/lists/arraylist/arraylist.go index f9e3543..c1af31f 100644 --- a/lists/arraylist/arraylist.go +++ b/lists/arraylist/arraylist.go @@ -11,9 +11,10 @@ package arraylist import ( "fmt" + "strings" + "github.com/emirpasic/gods/lists" "github.com/emirpasic/gods/utils" - "strings" ) func assertListImplementation() { @@ -36,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 bd85b18..51e4aee 100644 --- a/lists/doublylinkedlist/doublylinkedlist.go +++ b/lists/doublylinkedlist/doublylinkedlist.go @@ -11,9 +11,10 @@ package doublylinkedlist import ( "fmt" + "strings" + "github.com/emirpasic/gods/lists" "github.com/emirpasic/gods/utils" - "strings" ) func assertListImplementation() { @@ -38,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 139925b..d48afc8 100644 --- a/lists/singlylinkedlist/singlylinkedlist.go +++ b/lists/singlylinkedlist/singlylinkedlist.go @@ -11,9 +11,10 @@ package singlylinkedlist import ( "fmt" + "strings" + "github.com/emirpasic/gods/lists" "github.com/emirpasic/gods/utils" - "strings" ) func assertListImplementation() { @@ -37,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 {