FAQ
Hi,

I have published a new package in Gibhub, I was hoping some experts with Go
could give me some constructive feedback.

https://github.com/gatmac/immutablelist

I am a newbie with Golang, and in fact I am not even a professional
developer in any language, so please state your scathing criticisms in a
kindly way. :-)

Regards,
Greg

PACKAGE DOCUMENTATION

package immutablelist
     import "github.com/gatmac/immutablelist"

     Package immutablelist implements a single, nonmutable linked list. This
     immutablelist for Golang is modelled loosely on the List[] in Scala.
     Example use case:

lis := immutablelist.New("Lists", "immutable", "with", "Fun")
for e := lis; e.Head() != nil; e = e.Tail() {
fmt.Println(e.Head()) // Do something
}


TYPES

type Element struct {
     // contains filtered or unexported fields
}
     Element is the core element of a Linked List.


func New(values ...interface{}) *Element
     New() returns a new list with elements from the provided values.


func NewFromList(ml *list.List) *Element
     NewFromList() creates a new immutable list from a mutable container/list
     in the Go library.


func (e *Element) Add(v interface{}) *Element
     Add() adds a new value to the front / head of the list. See Cons().

func (e *Element) AddArray(values ...interface{}) *Element
     AddArray() adds an array of values to the front of the list.

func (e1 *Element) Append(e2 *Element) *Element
     Append() append the provided list to the end of the called list.

func (e *Element) Cons(v interface{}) *Element
     Cons() is the core func that adds new values to the front of the list.
     All roads lead through Cons().

func (e *Element) Contains(v interface{}) bool
     Contains() tests whether this list contains a given value as an element.

func (e *Element) Count(f func(interface{}) bool) uint
     Count() returns the number of elements in the list which satisfy a
     predicate function.

func (e1 *Element) Equals(e2 *Element) bool
     Equals() returns whether the list contains the same elements as another
     list.

func (e *Element) Exists(f func(interface{}) bool) bool
     Exists() determines whether any value of the list satisfies the
     predicate function.

func (e *Element) Filter(f func(interface{}) bool) *Element
     Filter() returns a new list of all elements that satisfy the predicate
     function. If all elements satisfy the predicate, the original list is
     returned. Example usage of Filter(): FilterInt := func(x interface{})
     bool { return x.(int)%5 == 0 } // Divisible by 5 newIntList :=
     intList.Filter(FilterInt)

func (e *Element) FilterNot(f func(interface{}) bool) *Element
     FilterNot() returns a new list of elements that do not satisfy the
     predicate function. See Filter().

func (e *Element) Find(f func(interface{}) bool) int
     Find() returns the first element of the list satisfying a predicate
     function (base 0). Returns -1 if none.

func (e *Element) Fold(f func(interface{}, interface{}) interface{}, zero
interface{}) interface{}
     Fold() folds the elements of this list using the specified associative
     binary operator. Example usage of Fold():

l1 := immutablelist.New(1, 2, 3, 4, 5, 6)
concatint := func(x interface{}, y interface{}) interface{} {
return x.(string) + ", " + strconv.FormatInt(int64(y.(int)), 10)
}
sumint := func(x interface{}, y interface{}) interface{} { return x.(int) +
y.(int) }
fmt.Println(l1.Fold(concatint, ""), " = ", l1.Fold(sumint, 0))

func (e *Element) ForAll(f func(interface{}) bool) bool
     ForAll() determines whether all elements satisfy the predicate function.

func (e *Element) ForEach(f func(interface{}) interface{}) bool
     ForEach() executes the function on each element sequentially. ForEach()
     returns after all the functions have completed.

func (e *Element) ForEachGo(f func(interface{}) interface{}) bool
     ForEachGo() executes the function on each element simultaneously using
     go. ForEachGo() returns immediately.

func (e *Element) Head() interface{}
     Head() returns the value in the first element in the list.

func (e *Element) InsertAt(v interface{}, n uint) *Element
     InsertAt() inserts a new value at the specified place in the list. The
     first element is numbered 0. l.Insert("New Element", 2) will insert at
     position 2, which is the third element in the new list.

func (e *Element) IsDefinedAt(n uint) bool
     IsDefinedAt() tests whether this list contains given index.

func (e *Element) IsEmpty() bool
     IsEmpty() returns true of the list contains no data elements.

func (e *Element) Last() interface{}
     Last() returns the value of the last element.

func (e *Element) Len() uint
     Len() returns the number of elements in the list.

func (e *Element) Map(f func(interface{}) interface{}) *Element
     Map() returns a new list whose elements are the output of the function
     applied to the elemments of the original list. Example: l2 :=
     l1.Map(func(x interface{}) interface{} { return 2 * x.(int) })

func (e *Element) Next() *Element
     Next() returns the next element(s) of the list. See Tail().

func (e *Element) Reverse() *Element
     Reverse() provides the original list in reverse order.

func (e *Element) SplitAt(n uint) (*Element, *Element)
     SplitAt() returns two lists. New(1, 2, 3, 4, 5).SplitAt(3) will return
     lists { 1, 2, 3 } and { 4, 5 }.

func (e *Element) Tail() *Element
     Tail() returns the next element of the list. It is used for stepping
     through the list.

func (e *Element) Take(n uint) *Element
     Take(n) returns a new list of the first n elements.

func (e *Element) TakeAt(n uint) interface{}
     TakeAt(n) returns the data element at position n (base 0).

func (e *Element) TakeFrom(n uint) *Element
     TakeFrom(n) returns the elements starting from position n (base 0).

func (e *Element) TakeRight(n uint) *Element
     TakeRight() returns the rightmost n elements from the end of the list.

func (e *Element) To() *Element
     To() returns a new list of elements copied from the original list.

func (e *Element) ToArray() []interface{}
     ToArray() returns an array of the elements of the list.

func (e *Element) ToList() *list.List
     ToList() returns a dual-linked container/list from the Go library.

func (e *Element) ToString(f func(interface{}) string) string
     ToString() provides a printable string of the list, in the form of "(v1,
     v2, v3)" The provided function tells ToString() how to render the data
     into a string. Example usage of ToSring():

PrintInt := func(x interface{}) string { return
strconv.FormatInt(int64(x.(int)), 10) }
fmt.Println(mylistofInt.ToString(PrintInt))



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Henrik Johansson at Nov 29, 2013 at 8:14 am
    Looks good at my first glance but I am just curious as to where the
    immutability comes into play?
    It seems full of mutating methods adding to the list for example.

    / Henrik


    On Fri, Nov 29, 2013 at 9:04 AM, Gregory Tucker wrote:

    Hi,

    I have published a new package in Gibhub, I was hoping some experts with
    Go could give me some constructive feedback.

    https://github.com/gatmac/immutablelist

    I am a newbie with Golang, and in fact I am not even a professional
    developer in any language, so please state your scathing criticisms in a
    kindly way. :-)

    Regards,
    Greg

    PACKAGE DOCUMENTATION

    package immutablelist
    import "github.com/gatmac/immutablelist"

    Package immutablelist implements a single, nonmutable linked list. This
    immutablelist for Golang is modelled loosely on the List[] in Scala.
    Example use case:

    lis := immutablelist.New("Lists", "immutable", "with", "Fun")
    for e := lis; e.Head() != nil; e = e.Tail() {
    fmt.Println(e.Head()) // Do something
    }


    TYPES

    type Element struct {
    // contains filtered or unexported fields
    }
    Element is the core element of a Linked List.


    func New(values ...interface{}) *Element
    New() returns a new list with elements from the provided values.


    func NewFromList(ml *list.List) *Element
    NewFromList() creates a new immutable list from a mutable
    container/list
    in the Go library.


    func (e *Element) Add(v interface{}) *Element
    Add() adds a new value to the front / head of the list. See Cons().

    func (e *Element) AddArray(values ...interface{}) *Element
    AddArray() adds an array of values to the front of the list.

    func (e1 *Element) Append(e2 *Element) *Element
    Append() append the provided list to the end of the called list.

    func (e *Element) Cons(v interface{}) *Element
    Cons() is the core func that adds new values to the front of the list.
    All roads lead through Cons().

    func (e *Element) Contains(v interface{}) bool
    Contains() tests whether this list contains a given value as an
    element.

    func (e *Element) Count(f func(interface{}) bool) uint
    Count() returns the number of elements in the list which satisfy a
    predicate function.

    func (e1 *Element) Equals(e2 *Element) bool
    Equals() returns whether the list contains the same elements as another
    list.

    func (e *Element) Exists(f func(interface{}) bool) bool
    Exists() determines whether any value of the list satisfies the
    predicate function.

    func (e *Element) Filter(f func(interface{}) bool) *Element
    Filter() returns a new list of all elements that satisfy the predicate
    function. If all elements satisfy the predicate, the original list is
    returned. Example usage of Filter(): FilterInt := func(x interface{})
    bool { return x.(int)%5 == 0 } // Divisible by 5 newIntList :=
    intList.Filter(FilterInt)

    func (e *Element) FilterNot(f func(interface{}) bool) *Element
    FilterNot() returns a new list of elements that do not satisfy the
    predicate function. See Filter().

    func (e *Element) Find(f func(interface{}) bool) int
    Find() returns the first element of the list satisfying a predicate
    function (base 0). Returns -1 if none.

    func (e *Element) Fold(f func(interface{}, interface{}) interface{}, zero
    interface{}) interface{}
    Fold() folds the elements of this list using the specified associative
    binary operator. Example usage of Fold():

    l1 := immutablelist.New(1, 2, 3, 4, 5, 6)
    concatint := func(x interface{}, y interface{}) interface{} {
    return x.(string) + ", " + strconv.FormatInt(int64(y.(int)), 10)
    }
    sumint := func(x interface{}, y interface{}) interface{} { return x.(int)
    + y.(int) }
    fmt.Println(l1.Fold(concatint, ""), " = ", l1.Fold(sumint, 0))

    func (e *Element) ForAll(f func(interface{}) bool) bool
    ForAll() determines whether all elements satisfy the predicate
    function.

    func (e *Element) ForEach(f func(interface{}) interface{}) bool
    ForEach() executes the function on each element sequentially. ForEach()
    returns after all the functions have completed.

    func (e *Element) ForEachGo(f func(interface{}) interface{}) bool
    ForEachGo() executes the function on each element simultaneously using
    go. ForEachGo() returns immediately.

    func (e *Element) Head() interface{}
    Head() returns the value in the first element in the list.

    func (e *Element) InsertAt(v interface{}, n uint) *Element
    InsertAt() inserts a new value at the specified place in the list. The
    first element is numbered 0. l.Insert("New Element", 2) will insert at
    position 2, which is the third element in the new list.

    func (e *Element) IsDefinedAt(n uint) bool
    IsDefinedAt() tests whether this list contains given index.

    func (e *Element) IsEmpty() bool
    IsEmpty() returns true of the list contains no data elements.

    func (e *Element) Last() interface{}
    Last() returns the value of the last element.

    func (e *Element) Len() uint
    Len() returns the number of elements in the list.

    func (e *Element) Map(f func(interface{}) interface{}) *Element
    Map() returns a new list whose elements are the output of the function
    applied to the elemments of the original list. Example: l2 :=
    l1.Map(func(x interface{}) interface{} { return 2 * x.(int) })

    func (e *Element) Next() *Element
    Next() returns the next element(s) of the list. See Tail().

    func (e *Element) Reverse() *Element
    Reverse() provides the original list in reverse order.

    func (e *Element) SplitAt(n uint) (*Element, *Element)
    SplitAt() returns two lists. New(1, 2, 3, 4, 5).SplitAt(3) will return
    lists { 1, 2, 3 } and { 4, 5 }.

    func (e *Element) Tail() *Element
    Tail() returns the next element of the list. It is used for stepping
    through the list.

    func (e *Element) Take(n uint) *Element
    Take(n) returns a new list of the first n elements.

    func (e *Element) TakeAt(n uint) interface{}
    TakeAt(n) returns the data element at position n (base 0).

    func (e *Element) TakeFrom(n uint) *Element
    TakeFrom(n) returns the elements starting from position n (base 0).

    func (e *Element) TakeRight(n uint) *Element
    TakeRight() returns the rightmost n elements from the end of the list.

    func (e *Element) To() *Element
    To() returns a new list of elements copied from the original list.

    func (e *Element) ToArray() []interface{}
    ToArray() returns an array of the elements of the list.

    func (e *Element) ToList() *list.List
    ToList() returns a dual-linked container/list from the Go library.

    func (e *Element) ToString(f func(interface{}) string) string
    ToString() provides a printable string of the list, in the form of
    "(v1,
    v2, v3)" The provided function tells ToString() how to render the data
    into a string. Example usage of ToSring():

    PrintInt := func(x interface{}) string { return
    strconv.FormatInt(int64(x.(int)), 10) }
    fmt.Println(mylistofInt.ToString(PrintInt))



    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Gregory Tucker at Nov 29, 2013 at 8:23 am
    Immutable lists prepend new elements to the front of the list. Existing elements are never changed, they are simply orphaned and GC'd. Individual Goroutines or functions are free to add new elements, or make changes via copies, but it won't affect the data seen by the other Goroutines.

    - G
    On Nov 29, 2013, at 5:14 PM, Henrik Johansson wrote:

    Looks good at my first glance but I am just curious as to where the immutability comes into play?
    It seems full of mutating methods adding to the list for example.

    / Henrik



    On Fri, Nov 29, 2013 at 9:04 AM, Gregory Tucker wrote:
    Hi,

    I have published a new package in Gibhub, I was hoping some experts with Go could give me some constructive feedback.

    https://github.com/gatmac/immutablelist

    I am a newbie with Golang, and in fact I am not even a professional developer in any language, so please state your scathing criticisms in a kindly way. :-)

    Regards,
    Greg

    PACKAGE DOCUMENTATION

    package immutablelist
    import "github.com/gatmac/immutablelist"

    Package immutablelist implements a single, nonmutable linked list. This
    immutablelist for Golang is modelled loosely on the List[] in Scala.
    Example use case:

    lis := immutablelist.New("Lists", "immutable", "with", "Fun")
    for e := lis; e.Head() != nil; e = e.Tail() {
    fmt.Println(e.Head()) // Do something
    }


    TYPES

    type Element struct {
    // contains filtered or unexported fields
    }
    Element is the core element of a Linked List.


    func New(values ...interface{}) *Element
    New() returns a new list with elements from the provided values.


    func NewFromList(ml *list.List) *Element
    NewFromList() creates a new immutable list from a mutable container/list
    in the Go library.


    func (e *Element) Add(v interface{}) *Element
    Add() adds a new value to the front / head of the list. See Cons().

    func (e *Element) AddArray(values ...interface{}) *Element
    AddArray() adds an array of values to the front of the list.

    func (e1 *Element) Append(e2 *Element) *Element
    Append() append the provided list to the end of the called list.

    func (e *Element) Cons(v interface{}) *Element
    Cons() is the core func that adds new values to the front of the list.
    All roads lead through Cons().

    func (e *Element) Contains(v interface{}) bool
    Contains() tests whether this list contains a given value as an element.

    func (e *Element) Count(f func(interface{}) bool) uint
    Count() returns the number of elements in the list which satisfy a
    predicate function.

    func (e1 *Element) Equals(e2 *Element) bool
    Equals() returns whether the list contains the same elements as another
    list.

    func (e *Element) Exists(f func(interface{}) bool) bool
    Exists() determines whether any value of the list satisfies the
    predicate function.

    func (e *Element) Filter(f func(interface{}) bool) *Element
    Filter() returns a new list of all elements that satisfy the predicate
    function. If all elements satisfy the predicate, the original list is
    returned. Example usage of Filter(): FilterInt := func(x interface{})
    bool { return x.(int)%5 == 0 } // Divisible by 5 newIntList :=
    intList.Filter(FilterInt)

    func (e *Element) FilterNot(f func(interface{}) bool) *Element
    FilterNot() returns a new list of elements that do not satisfy the
    predicate function. See Filter().

    func (e *Element) Find(f func(interface{}) bool) int
    Find() returns the first element of the list satisfying a predicate
    function (base 0). Returns -1 if none.

    func (e *Element) Fold(f func(interface{}, interface{}) interface{}, zero interface{}) interface{}
    Fold() folds the elements of this list using the specified associative
    binary operator. Example usage of Fold():

    l1 := immutablelist.New(1, 2, 3, 4, 5, 6)
    concatint := func(x interface{}, y interface{}) interface{} {
    return x.(string) + ", " + strconv.FormatInt(int64(y.(int)), 10)
    }
    sumint := func(x interface{}, y interface{}) interface{} { return x.(int) + y.(int) }
    fmt.Println(l1.Fold(concatint, ""), " = ", l1.Fold(sumint, 0))

    func (e *Element) ForAll(f func(interface{}) bool) bool
    ForAll() determines whether all elements satisfy the predicate function.

    func (e *Element) ForEach(f func(interface{}) interface{}) bool
    ForEach() executes the function on each element sequentially. ForEach()
    returns after all the functions have completed.

    func (e *Element) ForEachGo(f func(interface{}) interface{}) bool
    ForEachGo() executes the function on each element simultaneously using
    go. ForEachGo() returns immediately.

    func (e *Element) Head() interface{}
    Head() returns the value in the first element in the list.

    func (e *Element) InsertAt(v interface{}, n uint) *Element
    InsertAt() inserts a new value at the specified place in the list. The
    first element is numbered 0. l.Insert("New Element", 2) will insert at
    position 2, which is the third element in the new list.

    func (e *Element) IsDefinedAt(n uint) bool
    IsDefinedAt() tests whether this list contains given index.

    func (e *Element) IsEmpty() bool
    IsEmpty() returns true of the list contains no data elements.

    func (e *Element) Last() interface{}
    Last() returns the value of the last element.

    func (e *Element) Len() uint
    Len() returns the number of elements in the list.

    func (e *Element) Map(f func(interface{}) interface{}) *Element
    Map() returns a new list whose elements are the output of the function
    applied to the elemments of the original list. Example: l2 :=
    l1.Map(func(x interface{}) interface{} { return 2 * x.(int) })

    func (e *Element) Next() *Element
    Next() returns the next element(s) of the list. See Tail().

    func (e *Element) Reverse() *Element
    Reverse() provides the original list in reverse order.

    func (e *Element) SplitAt(n uint) (*Element, *Element)
    SplitAt() returns two lists. New(1, 2, 3, 4, 5).SplitAt(3) will return
    lists { 1, 2, 3 } and { 4, 5 }.

    func (e *Element) Tail() *Element
    Tail() returns the next element of the list. It is used for stepping
    through the list.

    func (e *Element) Take(n uint) *Element
    Take(n) returns a new list of the first n elements.

    func (e *Element) TakeAt(n uint) interface{}
    TakeAt(n) returns the data element at position n (base 0).

    func (e *Element) TakeFrom(n uint) *Element
    TakeFrom(n) returns the elements starting from position n (base 0).

    func (e *Element) TakeRight(n uint) *Element
    TakeRight() returns the rightmost n elements from the end of the list.

    func (e *Element) To() *Element
    To() returns a new list of elements copied from the original list.

    func (e *Element) ToArray() []interface{}
    ToArray() returns an array of the elements of the list.

    func (e *Element) ToList() *list.List
    ToList() returns a dual-linked container/list from the Go library.

    func (e *Element) ToString(f func(interface{}) string) string
    ToString() provides a printable string of the list, in the form of "(v1,
    v2, v3)" The provided function tells ToString() how to render the data
    into a string. Example usage of ToSring():

    PrintInt := func(x interface{}) string { return strconv.FormatInt(int64(x.(int)), 10) }
    fmt.Println(mylistofInt.ToString(PrintInt))




    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Henrik Johansson at Nov 29, 2013 at 8:25 am
    In that case I think you still have to protect the structures from
    concurrent usage using locks.

    On Fri, Nov 29, 2013 at 9:22 AM, Gregory Tucker wrote:

    Immutable lists prepend new elements to the front of the list. Existing
    elements are never changed, they are simply orphaned and GC'd. Individual
    Goroutines or functions are free to add new elements, or make changes via
    copies, but it won't affect the data seen by the other Goroutines.

    - G

    On Nov 29, 2013, at 5:14 PM, Henrik Johansson wrote:

    Looks good at my first glance but I am just curious as to where the
    immutability comes into play?
    It seems full of mutating methods adding to the list for example.

    / Henrik


    On Fri, Nov 29, 2013 at 9:04 AM, Gregory Tucker wrote:

    Hi,

    I have published a new package in Gibhub, I was hoping some experts with
    Go could give me some constructive feedback.

    https://github.com/gatmac/immutablelist

    I am a newbie with Golang, and in fact I am not even a professional
    developer in any language, so please state your scathing criticisms in a
    kindly way. :-)

    Regards,
    Greg

    PACKAGE DOCUMENTATION

    package immutablelist
    import "github.com/gatmac/immutablelist"

    Package immutablelist implements a single, nonmutable linked list.
    This
    immutablelist for Golang is modelled loosely on the List[] in Scala.
    Example use case:

    lis := immutablelist.New("Lists", "immutable", "with", "Fun")
    for e := lis; e.Head() != nil; e = e.Tail() {
    fmt.Println(e.Head()) // Do something
    }


    TYPES

    type Element struct {
    // contains filtered or unexported fields
    }
    Element is the core element of a Linked List.


    func New(values ...interface{}) *Element
    New() returns a new list with elements from the provided values.


    func NewFromList(ml *list.List) *Element
    NewFromList() creates a new immutable list from a mutable
    container/list
    in the Go library.


    func (e *Element) Add(v interface{}) *Element
    Add() adds a new value to the front / head of the list. See Cons().

    func (e *Element) AddArray(values ...interface{}) *Element
    AddArray() adds an array of values to the front of the list.

    func (e1 *Element) Append(e2 *Element) *Element
    Append() append the provided list to the end of the called list.

    func (e *Element) Cons(v interface{}) *Element
    Cons() is the core func that adds new values to the front of the list.
    All roads lead through Cons().

    func (e *Element) Contains(v interface{}) bool
    Contains() tests whether this list contains a given value as an
    element.

    func (e *Element) Count(f func(interface{}) bool) uint
    Count() returns the number of elements in the list which satisfy a
    predicate function.

    func (e1 *Element) Equals(e2 *Element) bool
    Equals() returns whether the list contains the same elements as
    another
    list.

    func (e *Element) Exists(f func(interface{}) bool) bool
    Exists() determines whether any value of the list satisfies the
    predicate function.

    func (e *Element) Filter(f func(interface{}) bool) *Element
    Filter() returns a new list of all elements that satisfy the predicate
    function. If all elements satisfy the predicate, the original list is
    returned. Example usage of Filter(): FilterInt := func(x interface{})
    bool { return x.(int)%5 == 0 } // Divisible by 5 newIntList :=
    intList.Filter(FilterInt)

    func (e *Element) FilterNot(f func(interface{}) bool) *Element
    FilterNot() returns a new list of elements that do not satisfy the
    predicate function. See Filter().

    func (e *Element) Find(f func(interface{}) bool) int
    Find() returns the first element of the list satisfying a predicate
    function (base 0). Returns -1 if none.

    func (e *Element) Fold(f func(interface{}, interface{}) interface{}, zero
    interface{}) interface{}
    Fold() folds the elements of this list using the specified associative
    binary operator. Example usage of Fold():

    l1 := immutablelist.New(1, 2, 3, 4, 5, 6)
    concatint := func(x interface{}, y interface{}) interface{} {
    return x.(string) + ", " + strconv.FormatInt(int64(y.(int)), 10)
    }
    sumint := func(x interface{}, y interface{}) interface{} { return
    x.(int) + y.(int) }
    fmt.Println(l1.Fold(concatint, ""), " = ", l1.Fold(sumint, 0))

    func (e *Element) ForAll(f func(interface{}) bool) bool
    ForAll() determines whether all elements satisfy the predicate
    function.

    func (e *Element) ForEach(f func(interface{}) interface{}) bool
    ForEach() executes the function on each element sequentially.
    ForEach()
    returns after all the functions have completed.

    func (e *Element) ForEachGo(f func(interface{}) interface{}) bool
    ForEachGo() executes the function on each element simultaneously using
    go. ForEachGo() returns immediately.

    func (e *Element) Head() interface{}
    Head() returns the value in the first element in the list.

    func (e *Element) InsertAt(v interface{}, n uint) *Element
    InsertAt() inserts a new value at the specified place in the list. The
    first element is numbered 0. l.Insert("New Element", 2) will insert at
    position 2, which is the third element in the new list.

    func (e *Element) IsDefinedAt(n uint) bool
    IsDefinedAt() tests whether this list contains given index.

    func (e *Element) IsEmpty() bool
    IsEmpty() returns true of the list contains no data elements.

    func (e *Element) Last() interface{}
    Last() returns the value of the last element.

    func (e *Element) Len() uint
    Len() returns the number of elements in the list.

    func (e *Element) Map(f func(interface{}) interface{}) *Element
    Map() returns a new list whose elements are the output of the function
    applied to the elemments of the original list. Example: l2 :=
    l1.Map(func(x interface{}) interface{} { return 2 * x.(int) })

    func (e *Element) Next() *Element
    Next() returns the next element(s) of the list. See Tail().

    func (e *Element) Reverse() *Element
    Reverse() provides the original list in reverse order.

    func (e *Element) SplitAt(n uint) (*Element, *Element)
    SplitAt() returns two lists. New(1, 2, 3, 4, 5).SplitAt(3) will return
    lists { 1, 2, 3 } and { 4, 5 }.

    func (e *Element) Tail() *Element
    Tail() returns the next element of the list. It is used for stepping
    through the list.

    func (e *Element) Take(n uint) *Element
    Take(n) returns a new list of the first n elements.

    func (e *Element) TakeAt(n uint) interface{}
    TakeAt(n) returns the data element at position n (base 0).

    func (e *Element) TakeFrom(n uint) *Element
    TakeFrom(n) returns the elements starting from position n (base 0).

    func (e *Element) TakeRight(n uint) *Element
    TakeRight() returns the rightmost n elements from the end of the list.

    func (e *Element) To() *Element
    To() returns a new list of elements copied from the original list.

    func (e *Element) ToArray() []interface{}
    ToArray() returns an array of the elements of the list.

    func (e *Element) ToList() *list.List
    ToList() returns a dual-linked container/list from the Go library.

    func (e *Element) ToString(f func(interface{}) string) string
    ToString() provides a printable string of the list, in the form of
    "(v1,
    v2, v3)" The provided function tells ToString() how to render the data
    into a string. Example usage of ToSring():

    PrintInt := func(x interface{}) string { return
    strconv.FormatInt(int64(x.(int)), 10) }
    fmt.Println(mylistofInt.ToString(PrintInt))




    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Gregory Tucker at Nov 29, 2013 at 8:39 am
    You may be correct--I am looking into memory locking, concurrency, and parallelism in Golang right now. I had assumed locks were necessary only where many functions may attempt to read and write the same structure. In contrast I am attempting to prevent any writes to the data elements once they are created.

    Greg
    On Nov 29, 2013, at 5:25 PM, Henrik Johansson wrote:

    In that case I think you still have to protect the structures from concurrent usage using locks.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Tamás Gulácsi at Nov 29, 2013 at 9:22 am
    Hi,

    1. Every "modification" copyies the whole list?
    2. How do you treat pointer Element ? I mean
    a, b := "a", "b"
    lst := New(&a, &b)
    b = "c"
    fmt.Printf(lst)

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Gregory Tucker at Nov 29, 2013 at 5:50 pm
    1. No, the Cons (Add) function creates and returns a new element that points to the existing list. However some operations such as Reverse() will duplicate all the elements.

    2. Good question, I will need to do some testing on pointers. Is there a type test available for this case?

    Regards,
    Greg

    On 2013/11/29, at 18:22, Tamás Gulácsi wrote:

    Hi,

    1. Every "modification" copyies the whole list?
    2. How do you treat pointer Element ? I mean
    a, b := "a", "b"
    lst := New(&a, &b)
    b = "c"
    fmt.Printf(lst)
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Josh Hoak at Nov 29, 2013 at 8:57 pm
    Usually when people create list-like containers, they have a List
    abstraction around the Element/Node class. Relying only on elements as
    you've done means that operations like Len() and Last() are O(n) rather
    than O(1), which is unusual and not performant. Not having a distinction
    between an Element/Node and the full List also means that Tail returns a
    single element. This results in Tail() and Next() returning the same thing,
    which is confusing from an API perspective.

    On Fri, Nov 29, 2013 at 10:50 AM, Gregory Tucker wrote:

    1. No, the Cons (Add) function creates and returns a new element that
    points to the existing list. However some operations such as Reverse() will
    duplicate all the elements.

    2. Good question, I will need to do some testing on pointers. Is there a
    type test available for this case?

    Regards,
    Greg

    On 2013/11/29, at 18:22, Tamás Gulácsi wrote:

    Hi,

    1. Every "modification" copyies the whole list?
    2. How do you treat pointer Element ? I mean
    a, b := "a", "b"
    lst := New(&a, &b)
    b = "c"
    fmt.Printf(lst)
    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Gregory Tucker at Nov 30, 2013 at 6:16 am
    Thanks for the feedback. I updated the Cons(0 function to test for pointers and to include a copy of the data.

    Greg
    On Nov 29, 2013, at 6:22 PM, Tamás Gulácsi wrote:

    2. How do you treat pointer Element ? I mean
    a, b := "a", "b"
    lst := New(&a, &b)
    b = "c"
    fmt.Printf(lst)
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 29, '13 at 8:04a
activeNov 30, '13 at 6:16a
posts9
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase