API/Stack

Enumerable.prototype:ToStack()

Make a new Stack filled with the contents of the current Enumerable

Return value

a Stack


Stack.FromArguments(...)

Construct and return a new Stack based on the arguments provided

Parameters

...
a tuple of arguments to fill the stack with

Return value

a Stack

Usage

local stack = Stack.FromArguments()
local stack = Stack.FromArguments(1, 2, 3)
local stack = Stack.FromArguments(nil, nil, 5)


Stack.New(sequence)

Construct and return a new Stack

Parameters

sequence
optional: The sequence to fill the stack with

Return value

a Stack

Usage

local stack = Stack.New()
local stack = Stack.New({ 1, 2, 3 })
local stack = Stack.New(Enumerable.RangeTo(1, 10))


Stack.prototype:Clear()

Clear all elements from the Stack

Usage

stack:Clear()


Stack.prototype:Clone()

Make a shallow clone of the Stack.

Usage

local other = stack:Clone()


Stack.prototype:GetEnumerator()

Return an Enumerator for the current Stack

Return value

an Enumerator


Stack.prototype:IsReadOnly()

Return whether the Stack is read-only, always returns false.

Return value

a boolean

Usage

local read_only = stack:IsReadOnly()


Stack.prototype:Peek()

Returns the object at the top of the Stack.
This will error if the Stack is empty.

Return value

The element at the top of the Stack.

Usage

local item = stack:Peek()


Stack.prototype:Pop()

Removes and returns the object at the top of the Stack.
This will error if the Stack is empty.

Return value

The removed element at the top of the Stack.

Usage

local item = stack:Pop()


Stack.prototype:Push(item)

Inserts an element at the top of the Stack

Parameters

item
the element to push

Usage

stack:Push(5)
stack:Push(nil)


Stack.prototype:SetContract(contract)

Set a contract that will be verified against any existing elements and any added elements or changed values.
This is handy for if you want to verify that all values are strings or something like that. This will call :VerifyContract()

Parameters

contract
a function that is passed the element and should return whether the element is valid.

Usage

stack:SetContract(function(v) return type(v) == "string" end)


Stack.prototype:VerifyContract()

Verify that the contract for this Stack is valid for all elements in the Stack.
If there is no contract, this does nothing.

Usage

stack:VerifyContract()



Comments

Posts Quoted:
Reply
Clear All Quotes