Skip to content
This repository has been archived by the owner on Feb 9, 2020. It is now read-only.

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mndrix committed Feb 18, 2013
1 parent 33c5f69 commit 26a0e47
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions list.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
package ps

// List is a persistent list of possibly heterogenous values.
type List interface {
// IsNil returns true if the list is empty
IsNil() bool

// Cons returns a new list with val added onto the head
// Cons returns a new list with val as the head
Cons(val Any) List

// Head returns the first element in the list or panics if the list is empty
// Head returns the first element of the list;
// panics if the list is empty
Head() Any

// Tail returns the tail of this list or panics if the list is empty
// Tail returns a list with all elements except the head;
// panics if the list is empty
Tail() List

// Size returns the list's length
// Size returns the list's length. This takes O(1) time.
Size() int

// ForEach executes a callback for each value in the list
// ForEach executes a callback for each value in the list.
ForEach(f func(Any))

// Reverse returns a list with elements in opposite order as this list
// Reverse returns a list whose elements are in the opposite order as
// the original list.
Reverse() List
}

Expand All @@ -33,7 +37,9 @@ type list struct {
// An empty list shared by all lists
var nilList = &list{}

// NewList returns a new, empty list
// NewList returns a new, empty list. The result is a singly linked
// list implementation. All lists share an empty tail, so allocating
// empty lists is efficient in time and memory.
func NewList() List {
return nilList
}
Expand Down

0 comments on commit 26a0e47

Please sign in to comment.