Documentation
¶
Overview ¶
Package stack implements a persistent stack.
Index ¶
- type Stack
- func (s *Stack) AsTransient() *TStack
- func (s *Stack) Conj(elem interface{}) interface{}
- func (s *Stack) Equal(o interface{}) bool
- func (s *Stack) Find(value interface{}) (interface{}, bool)
- func (s *Stack) Length() int
- func (s *Stack) Pop() *Stack
- func (s *Stack) Push(elem interface{}) *Stack
- func (s *Stack) Range(do interface{})
- func (s *Stack) Reduce(fn interface{}, init interface{}) interface{}
- func (s *Stack) Reverse() *vector.Vector
- func (s *Stack) Seq() seq.Sequence
- func (s *Stack) String() string
- func (s *Stack) Top() interface{}
- func (s *Stack) Transform(actions ...func(*TStack) *TStack) *Stack
- type TStack
- func (s *TStack) AsPersistent() *Stack
- func (s *TStack) Find(value interface{}) (interface{}, bool)
- func (s *TStack) Length() int
- func (s *TStack) Pop() *TStack
- func (s *TStack) Push(elem interface{}) *TStack
- func (s *TStack) Range(do interface{})
- func (s *TStack) Reduce(fn interface{}, init interface{}) interface{}
- func (s *TStack) String() string
- func (s *TStack) Top() interface{}
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack is a persistent stack.
Example (Reverse) ¶
s := New(1, 2, 3, 4, 5) fmt.Println(s) fmt.Println(s.Reverse())
Output: [ 5 4 3 2 1 ] [1 2 3 4 5]
func From ¶
func From(value interface{}) *Stack
From will convert many go types to an immutable map. Converting some types is more efficient than others and the mechanisms are described below.
*Stack:
Used directly as it is already immutable.
*TStack:
AsPersistent is called on the value and the result used for the stack.
*Vector:
Used directly as the stack as it is already immutable.
*TVector:
AsPersistent is called on the value and the result used for the stack.
[]interface{}:
New is called with the elements.
seq.Sequable:
Seq is called on the value and the stack is built from the resulting sequence.
seq.Sequence:
The stack is built from the sequence. Care should be taken to provide finite sequences or the vector will grow without bound.
[]T:
The slice is converted to a vector using reflection.
func New ¶
func New(elems ...interface{}) *Stack
New converts as list of elements to a persistent stack.
func (*Stack) AsTransient ¶
AsTransient will return a mutable copy on write version of the stack.
func (*Stack) Conj ¶
func (s *Stack) Conj(elem interface{}) interface{}
Conj returns a new stack with the element as the top of the stack. Conj implements a generic mechanism for building collections.
func (*Stack) Equal ¶
Equal tests if two sets are Equal by comparing the entries of each. Equal implements the Equaler which allows for deep comparisons.
func (*Stack) Find ¶
Find whether the value exists in the stack by walking every value. Returns the value and whether or not it was found.
func (*Stack) Range ¶
func (s *Stack) Range(do interface{})
Range calls the passed in function on each element of the stack. The function passed in may be of many types:
func(value interface{}) bool:
Takes a value of any type and returns if the loop should continue. Useful to avoid reflection where not needed and to support heterogenous stacks.
func(value interface{})
Takes a value of any type. Useful to avoid reflection where not needed and to support heterogenous stacks.
func(value T) bool:
Takes a value of the type of element stored in the stack and returns if the loop should continue. Useful for homogeneous stacks. Is called with reflection and will panic if the type is incorrect.
func(value T)
Takes a value of the type of element stored in the stack and returns if the loop should continue. Useful for homogeneous stacks. Is called with reflection and will panic if the type is incorrect.
Range will panic if passed anything that doesn't match one of these signatures
func (*Stack) Reduce ¶
func (s *Stack) Reduce(fn interface{}, init interface{}) interface{}
Reduce is a fast mechanism for reducing a Stack. Reduce can take the following types as the fn:
func(init interface{}, value interface{}) interface{} func(init iT, v vT) oT
Reduce will panic if given any other function type.
func (*Stack) Seq ¶
Seq returns a representation of the stack as a sequence corresponding to the elements of the stack.
type TStack ¶
type TStack struct {
// contains filtered or unexported fields
}
func (*TStack) AsPersistent ¶
AsPersistent returns the an immutable version of the stack. Any transient operations performed after this will cause a panic.
func (*TStack) Find ¶
Find whether the value exists in the stack by walking every value. Returns the value and whether or not it was found.
func (*TStack) Range ¶
func (s *TStack) Range(do interface{})
Range calls the passed in function on each element of the stack. The function passed in may be of many types:
func(value interface{}) bool:
Takes a value of any type and returns if the loop should continue. Useful to avoid reflection where not needed and to support heterogenous stacks.
func(value interface{})
Takes a value of any type. Useful to avoid reflection where not needed and to support heterogenous stacks.
func(value T) bool:
Takes a value of the type of element stored in the stack and returns if the loop should continue. Useful for homogeneous stacks. Is called with reflection and will panic if the type is incorrect.
func(value T)
Takes a value of the type of element stored in the stack and returns if the loop should continue. Useful for homogeneous stacks. Is called with reflection and will panic if the type is incorrect.
Range will panic if passed anything that doesn't match one of these signatures
func (*TStack) Reduce ¶
func (s *TStack) Reduce(fn interface{}, init interface{}) interface{}
Reduce is a fast mechanism for reducing a Stack. Reduce can take the following types as the fn:
func(init interface{}, value interface{}) interface{} func(init iT, v vT) oT
Reduce will panic if given any other function type.