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.