Stack
A stack is a LIFO (last-in-first-out) data structure where new values are added, retrieved, and removed from the end.
Edit on GitHubThe default implementation is mutable, but an immutable stack
implementation is available in the Immutable submodule.
Added in 0.3.0
No other changes yet.
from "stack" include Stack
Type declarations included in the Stack module.
type Stack<a>
A mutable LIFO (last-in-first-out) data structure.
Functions and constants included in the Stack module.
Added in 0.6.0
No other changes yet.
make : (?size: Number) => Stack<a>
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 |
?size: The initial storage size of the stackReturns:
| type | description |
|---|---|
Stack<a> | An empty stack |
Stack<a>: An empty stackAdded in 0.6.0
No other changes yet.
isEmpty : (stack: Stack<a>) => Bool
Checks if the given stack contains no items.
Parameters:
| param | type | description |
|---|---|---|
stack | Stack<a> | The stack to check |
stack: The stack to checkReturns:
| type | description |
|---|---|
Bool | true if the stack has no items or false otherwise |
Bool: true if the stack has no items or false otherwiseAdded in 0.6.0
No other changes yet.
size : (stack: Stack<a>) => Number
Computes the size of the input stack.
Parameters:
| param | type | description |
|---|---|---|
stack | Stack<a> | The stack to inspect |
stack: The stack to inspectReturns:
| type | description |
|---|---|
Number | The count of the items in the stack |
Number: The count of the items in the stackAdded in 0.6.0
No other changes yet.
peek : (stack: Stack<a>) => Option<a>
Provides the value at the top of the stack, if it exists.
Parameters:
| param | type | description |
|---|---|---|
stack | Stack<a> | The stack to inspect |
stack: The stack to inspectReturns:
| type | description |
|---|---|
Option<a> | Some(value) containing the value at the top of the stack or None otherwise. |
Option<a>: Some(value) containing the value at the top of the stack or None otherwise.Added in 0.6.0
No other changes yet.
push : (value: a, stack: Stack<a>) => Void
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 |
value: The item to be addedstack: The stack being updatedAdded in 0.6.0
No other changes yet.
pop : (stack: Stack<a>) => Option<a>
Removes the item at the top of the stack.
Parameters:
| param | type | description |
|---|---|---|
stack | Stack<a> | The stack being updated |
stack: The stack being updatedReturns:
| type | description |
|---|---|
Option<a> | The element removed from the stack |
Option<a>: The element removed from the stackAdded in 0.6.0
No other changes yet.
clear : (stack: Stack<a>) => Void
Clears the stack by removing all of its elements
Parameters:
| param | type | description |
|---|---|---|
stack | Stack<a> | The stack to clear |
stack: The stack to clearAdded in 0.6.0
No other changes yet.
copy : (stack: Stack<a>) => Stack<a>
Produces a shallow copy of the input stack.
Parameters:
| param | type | description |
|---|---|---|
stack | Stack<a> | The stack to copy |
stack: The stack to copyReturns:
| type | description |
|---|---|
Stack<a> | A new stack containing the elements from the input |
Stack<a>: A new stack containing the elements from the inputAn immutable stack implementation.
Type declarations included in the Stack.Immutable module.
type ImmutableStack<a>
ImmutableStacks are immutable data structures that store their data in a List.
Functions and constants included in the Stack.Immutable module.
Added in 0.6.0
| version | changes |
|---|---|
0.5.4 | Originally a module root API |
empty : ImmutableStack<a>
An empty stack.
Added in 0.6.0
| version | changes |
|---|---|
0.3.0 | Originally a module root API |
isEmpty : (stack: ImmutableStack<a>) => Bool
Checks if the given stack contains no items.
Parameters:
| param | type | description |
|---|---|---|
stack | ImmutableStack<a> | The stack to check |
stack: The stack to checkReturns:
| type | description |
|---|---|
Bool | true if the stack has no items or false otherwise |
Bool: true if the stack has no items or false otherwiseAdded in 0.6.0
| version | changes |
|---|---|
0.3.0 | Originally a module root API |
0.3.1 | Rename from `head` to `peek` |
peek : (stack: ImmutableStack<a>) => Option<a>
Provides the value at the top of the stack, if it exists.
Parameters:
| param | type | description |
|---|---|---|
stack | ImmutableStack<a> | The stack to inspect |
stack: The stack to inspectReturns:
| type | description |
|---|---|
Option<a> | Some(value) containing the value at the top of the stack or None otherwise. |
Option<a>: Some(value) containing the value at the top of the stack or None otherwise.Added in 0.6.0
| version | changes |
|---|---|
0.3.0 | Originally a module root API |
push : (value: a, stack: ImmutableStack<a>) => ImmutableStack<a>
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 |
value: The item to be addedstack: The stack being updatedReturns:
| type | description |
|---|---|
ImmutableStack<a> | A new stack with the item added to the end |
ImmutableStack<a>: A new stack with the item added to the endAdded in 0.6.0
| version | changes |
|---|---|
0.3.0 | Originally a module root API |
pop : (stack: ImmutableStack<a>) => ImmutableStack<a>
Removes the item at the top of the stack.
Parameters:
| param | type | description |
|---|---|---|
stack | ImmutableStack<a> | The stack being updated |
stack: The stack being updatedReturns:
| type | description |
|---|---|
ImmutableStack<a> | A new stack with the last item removed |
ImmutableStack<a>: A new stack with the last item removedAdded in 0.6.0
| version | changes |
|---|---|
0.3.2 | Originally a module root API |
size : (stack: ImmutableStack<a>) => Number
Computes the size of the input stack.
Parameters:
| param | type | description |
|---|---|---|
stack | ImmutableStack<a> | The stack to inspect |
stack: The stack to inspectReturns:
| type | description |
|---|---|
Number | The count of the items in the stack |
Number: The count of the items in the stack