class Stack
class Stack
lib/collections/stack.tya:2
Stack provides the collections/Stack standard library API.
Source
# Stack provides the collections/Stack standard library API.
class Stack
# Stack.items stores instance state.
# @type Array
items: []
# Stack.initialize provides the collections/Stack standard library operation.
# @param values Array values value.
# @return Self the initialized object.
initialize: values = nil ->
if values == nil
self.items = []
else
self.items = values.slice(0, values.len())
# Stack.clear provides the collections/Stack standard library operation.
# @return Nil the resulting value.
clear: ->
self.items = []
self
# Stack.empty? provides the collections/Stack standard library operation.
# @return Boolean whether the condition is true.
empty?: ->
self.items.empty?()
# Stack.from_array provides the collections/Stack standard library operation.
# @param values Array values value.
# @return Array the resulting value.
from_array: values ->
Stack(values)
# Stack.len provides the collections/Stack standard library operation.
# @return Int the resulting value.
len: ->
self.items.len()
# Stack.new provides the collections/Stack standard library operation.
# @return Self the resulting value.
new: ->
Stack(nil)
# Stack.peek provides the collections/Stack standard library operation.
# @return Any the resulting value.
peek: ->
if self.empty?()
raise error("collections.Stack.peek: empty stack")
self.items[self.items.len() - 1]
# Stack.pop provides the collections/Stack standard library operation.
# @return Any the resulting value.
pop: ->
if self.empty?()
raise error("collections.Stack.pop: empty stack")
self.items.pop()
# Stack.push provides the collections/Stack standard library operation.
# @param value String value value.
# @return Any the resulting value.
push: value ->
self.items.push(value)
self
# Stack.to_array provides the collections/Stack standard library operation.
# @return Array the resulting value.
to_array: ->
self.items.slice(0, self.items.len())
Instance Variables
items
Stack.items
lib/collections/stack.tya:5
Stack.items stores instance state.
Source
# Stack.items stores instance state.
# @type Array
items: []
Methods
clear
Stack.clear()
lib/collections/stack.tya:18
Stack.clear provides the collections/Stack standard library operation.
Source
# Stack.clear provides the collections/Stack standard library operation.
# @return Nil the resulting value.
clear: ->
self.items = []
self
empty?
Stack.empty?()
lib/collections/stack.tya:24
Stack.empty? provides the collections/Stack standard library operation.
Source
# Stack.empty? provides the collections/Stack standard library operation.
# @return Boolean whether the condition is true.
empty?: ->
self.items.empty?()
from_array
Stack.from_array(values)
lib/collections/stack.tya:30
Stack.from_array provides the collections/Stack standard library operation.
Source
# Stack.from_array provides the collections/Stack standard library operation.
# @param values Array values value.
# @return Array the resulting value.
from_array: values ->
Stack(values)
initialize
Stack.initialize(values = nil)
lib/collections/stack.tya:10
Stack.initialize provides the collections/Stack standard library operation.
Source
# Stack.initialize provides the collections/Stack standard library operation.
# @param values Array values value.
# @return Self the initialized object.
initialize: values = nil ->
if values == nil
self.items = []
else
self.items = values.slice(0, values.len())
len
Stack.len()
lib/collections/stack.tya:35
Stack.len provides the collections/Stack standard library operation.
Source
# Stack.len provides the collections/Stack standard library operation.
# @return Int the resulting value.
len: ->
self.items.len()
new
Stack.new()
lib/collections/stack.tya:40
Stack.new provides the collections/Stack standard library operation.
Source
# Stack.new provides the collections/Stack standard library operation.
# @return Self the resulting value.
new: ->
Stack(nil)
peek
Stack.peek()
lib/collections/stack.tya:45
Stack.peek provides the collections/Stack standard library operation.
Source
# Stack.peek provides the collections/Stack standard library operation.
# @return Any the resulting value.
peek: ->
if self.empty?()
raise error("collections.Stack.peek: empty stack")
self.items[self.items.len() - 1]
pop
Stack.pop()
lib/collections/stack.tya:52
Stack.pop provides the collections/Stack standard library operation.
Source
# Stack.pop provides the collections/Stack standard library operation.
# @return Any the resulting value.
pop: ->
if self.empty?()
raise error("collections.Stack.pop: empty stack")
self.items.pop()
push
Stack.push(value)
lib/collections/stack.tya:60
Stack.push provides the collections/Stack standard library operation.
Source
# Stack.push provides the collections/Stack standard library operation.
# @param value String value value.
# @return Any the resulting value.
push: value ->
self.items.push(value)
self
to_array
Stack.to_array()
lib/collections/stack.tya:66
Stack.to_array provides the collections/Stack standard library operation.
Source
# Stack.to_array provides the collections/Stack standard library operation.
# @return Array the resulting value.
to_array: ->
self.items.slice(0, self.items.len())