ESC
No recent searches
Search by
Standard Library  /  Stack

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 GitHub

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.
from "stack" include Stack

Types

Type declarations included in the Stack module.

Stack.Stack

type Stack<a>

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.
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:

?size: The initial storage size of the stack

Returns:

Stack<a>: An empty stack

Stack.isEmpty

Added in 0.6.0 No other changes yet.
isEmpty : (stack: Stack<a>) => Bool

Checks if the given stack contains no items.

Parameters:

stack: The stack to check

Returns:

Bool: true if the stack has no items or false otherwise

Stack.size

Added in 0.6.0 No other changes yet.
size : (stack: Stack<a>) => Number

Computes the size of the input stack.

Parameters:

stack: The stack to inspect

Returns:

Number: The count of the items in the stack

Stack.peek

Added 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:

stack: The stack to inspect

Returns:

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.
push : (value: a, stack: Stack<a>) => Void

Adds a new item to the top of the stack.

Parameters:

value: The item to be added
stack: The stack being updated

Stack.pop

Added in 0.6.0 No other changes yet.
pop : (stack: Stack<a>) => Option<a>

Removes the item at the top of the stack.

Parameters:

stack: The stack being updated

Returns:

Option<a>: The element removed from the stack

Stack.clear

Added in 0.6.0 No other changes yet.
clear : (stack: Stack<a>) => Void

Clears the stack by removing all of its elements

Parameters:

stack: The stack to clear

Stack.copy

Added in 0.6.0 No other changes yet.
copy : (stack: Stack<a>) => Stack<a>

Produces a shallow copy of the input stack.

Parameters:

stack: The stack to copy

Returns:

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

type ImmutableStack<a>

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
versionchanges
0.5.4Originally a module root API
empty : ImmutableStack<a>

An empty stack.

Stack.Immutable.isEmpty

Added in 0.6.0
versionchanges
0.3.0Originally a module root API
isEmpty : (stack: ImmutableStack<a>) => Bool

Checks if the given stack contains no items.

Parameters:

stack: The stack to check

Returns:

Bool: true if the stack has no items or false otherwise

Stack.Immutable.peek

Added in 0.6.0
versionchanges
0.3.0Originally a module root API
0.3.1Rename from `head` to `peek`
peek : (stack: ImmutableStack<a>) => Option<a>

Provides the value at the top of the stack, if it exists.

Parameters:

stack: The stack to inspect

Returns:

Option<a>: Some(value) containing the value at the top of the stack or None otherwise.

Stack.Immutable.push

Added in 0.6.0
versionchanges
0.3.0Originally a module root API
push : (value: a, stack: ImmutableStack<a>) => ImmutableStack<a>

Adds a new item to the top of the stack.

Parameters:

value: The item to be added
stack: The stack being updated

Returns:

ImmutableStack<a>: A new stack with the item added to the end

Stack.Immutable.pop

Added in 0.6.0
versionchanges
0.3.0Originally a module root API
pop : (stack: ImmutableStack<a>) => ImmutableStack<a>

Removes the item at the top of the stack.

Parameters:

stack: The stack being updated

Returns:

ImmutableStack<a>: A new stack with the last item removed

Stack.Immutable.size

Added in 0.6.0
versionchanges
0.3.2Originally a module root API
size : (stack: ImmutableStack<a>) => Number

Computes the size of the input stack.

Parameters:

stack: The stack to inspect

Returns:

Number: The count of the items in the stack

Sign up for farm-to-inbox developer news

You can unsubscribe at any time. Read our privacy policy.

Copyright © 2024 The Grain Programming Language