Stack
Edit on GitHubA stack is a LIFO (last-in-first-out) data structure where new values are added, retrieved, and removed from the end.
The default implementation is mutable, but an immutable stack
implementation is available in the Immutable
submodule.
Added in 0.3.0
No other changes yet.
Types
Type declarations included in the Stack module.
Stack.Stack
A mutable LIFO (last-in-first-out) data structure.
Values
Functions and constants included in the Stack module.
Stack.make
Added in 0.6.0
No other changes yet.
Creates a new stack with an initial storage of the given size. As values are added or removed, the internal storage may grow or shrink. Generally, you won’t need to care about the storage size of your map and can use the default size.
Parameters:
param | type | description |
---|---|---|
?size |
Number |
The initial storage size of the stack |
Returns:
type | description |
---|---|
Stack<a> |
An empty stack |
Stack.isEmpty
Added in 0.6.0
No other changes yet.
Checks if the given stack contains no items.
Parameters:
param | type | description |
---|---|---|
stack |
Stack<a> |
The stack to check |
Returns:
type | description |
---|---|
Bool |
true if the stack has no items or false otherwise |
Stack.size
Added in 0.6.0
No other changes yet.
Computes the size of the input stack.
Parameters:
param | type | description |
---|---|---|
stack |
Stack<a> |
The stack to inspect |
Returns:
type | description |
---|---|
Number |
The count of the items in the stack |
Stack.peek
Added in 0.6.0
No other changes yet.
Provides the value at the top of the stack, if it exists.
Parameters:
param | type | description |
---|---|---|
stack |
Stack<a> |
The stack to inspect |
Returns:
type | description |
---|---|
Option<a> |
Some(value) containing the value at the top of the stack or None otherwise. |
Stack.push
Added in 0.6.0
No other changes yet.
Adds a new item to the top of the stack.
Parameters:
param | type | description |
---|---|---|
value |
a |
The item to be added |
stack |
Stack<a> |
The stack being updated |
Stack.pop
Added in 0.6.0
No other changes yet.
Removes the item at the top of the stack.
Parameters:
param | type | description |
---|---|---|
stack |
Stack<a> |
The stack being updated |
Returns:
type | description |
---|---|
Option<a> |
The element removed from the stack |
Stack.clear
Added in 0.6.0
No other changes yet.
Clears the stack by removing all of its elements
Parameters:
param | type | description |
---|---|---|
stack |
Stack<a> |
The stack to clear |
Stack.copy
Added in 0.6.0
No other changes yet.
Produces a shallow copy of the input stack.
Parameters:
param | type | description |
---|---|---|
stack |
Stack<a> |
The stack to copy |
Returns:
type | description |
---|---|
Stack<a> |
A new stack containing the elements from the input |
Stack.Immutable
An immutable stack implementation.
Types
Type declarations included in the Stack.Immutable module.
Stack.Immutable.ImmutableStack
ImmutableStacks are immutable data structures that store their data in a List.
Values
Functions and constants included in the Stack.Immutable module.
Stack.Immutable.empty
Added in 0.6.0
version | changes |
---|---|
0.5.4 | Originally a module root API |
An empty stack.
Stack.Immutable.isEmpty
Added in 0.6.0
version | changes |
---|---|
0.3.0 | Originally a module root API |
Checks if the given stack contains no items.
Parameters:
param | type | description |
---|---|---|
stack |
ImmutableStack<a> |
The stack to check |
Returns:
type | description |
---|---|
Bool |
true if the stack has no items or false otherwise |
Stack.Immutable.peek
Added in 0.6.0
version | changes |
---|---|
0.3.0 | Originally a module root API |
0.3.1 | Rename from `head` to `peek` |
Provides the value at the top of the stack, if it exists.
Parameters:
param | type | description |
---|---|---|
stack |
ImmutableStack<a> |
The stack to inspect |
Returns:
type | description |
---|---|
Option<a> |
Some(value) containing the value at the top of the stack or None otherwise. |
Stack.Immutable.push
Added in 0.6.0
version | changes |
---|---|
0.3.0 | Originally a module root API |
Adds a new item to the top of the stack.
Parameters:
param | type | description |
---|---|---|
value |
a |
The item to be added |
stack |
ImmutableStack<a> |
The stack being updated |
Returns:
type | description |
---|---|
ImmutableStack<a> |
A new stack with the item added to the end |
Stack.Immutable.pop
Added in 0.6.0
version | changes |
---|---|
0.3.0 | Originally a module root API |
Removes the item at the top of the stack.
Parameters:
param | type | description |
---|---|---|
stack |
ImmutableStack<a> |
The stack being updated |
Returns:
type | description |
---|---|
ImmutableStack<a> |
A new stack with the last item removed |
Stack.Immutable.size
Added in 0.6.0
version | changes |
---|---|
0.3.2 | Originally a module root API |
Computes the size of the input stack.
Parameters:
param | type | description |
---|---|---|
stack |
ImmutableStack<a> |
The stack to inspect |
Returns:
type | description |
---|---|
Number |
The count of the items in the stack |