golist

package module
v0.0.0-...-758ca83 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2013 License: MIT Imports: 4 Imported by: 0

README

golist Build Status Clone in Koding

python's list type implementation on go.

installation
$ go get github.com/emre/golist
Initialization of a new List
my_list := golist.New()
my_list := golist.New("Galatasaray", "Real Madrid")
Appending items
my_list.Append("Drogba")
my_list.Append("Bruma")
Extending list with another list
other_list := golist.New("Ronaldo", "Bale")
my_list.Extend(other_list)
Get an index for the element
index, err := my_list.Index("Drogba")
if err != nil {
	fmt.Println(err)
}
fmt.Println(index)
Counting items
my_list.Append("Drogba", "Drogba")
drogba_count := my_list.Count("Drogba")
fmt.Println(drogba_count)
Deleting items by value/index
// by value
my_list.Remove("Drogba")

// by index
my_list.Delete(0)
Pop items
// pops the item which of index zero.
value, err := my_list.Pop(0)

// pops latest item
value, err := my_list.Pop()
Reversing a List
goals_list := golist.New("18:Drogba", "56:Bale", "90+2:Sabri Sarioglu")
goals_list.Reverse()
Get the size of list
list_size := goals_list.Len()
Further documentation

Bitdeli Badge

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyListError  = "%v operation from empty list"
	OutOfRangeError = "%s index out of range"
)

Functions

This section is empty.

Types

type List

type List struct {
	// contains filtered or unexported fields
}

func New

func New(items ...interface{}) List

Returns a new List

func (*List) Append

func (l *List) Append(items ...interface{})

Adds an item to the end of the list data

func (*List) Count

func (l *List) Count(value interface{}) int

Return the number of times x appears in the list.

func (*List) Delete

func (l *List) Delete(index int) error

Delete the item at the given position in the list.

func (*List) Extend

func (l *List) Extend(target_list List)

Extend the list by appending all the items in te given list.

func (*List) Index

func (l *List) Index(value interface{}) (int, error)

Returns the index in the list of the first item whose value is x. It is an error if there is no such item.

func (*List) Insert

func (l *List) Insert(index int, value interface{})

Insert an item at a given position. The first argument is the index of the element before which to insert

func (*List) Len

func (l *List) Len() int

Returns the length of the list

func (*List) Pop

func (l *List) Pop(index ...interface{}) (interface{}, error)

Remove the index at the given position in the list, and return it. If no index is specified, removes and returns the last item in the list.

func (*List) Remove

func (l *List) Remove(value interface{}) error

Remove the first item from the list whose value is x. Returns an error if there is no such item exists.

func (*List) Reverse

func (l *List) Reverse()

Reverse the elements of the list, in place.

func (List) String

func (l List) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL