class Deque

class Deque

lib/collections/deque.tya:2

Deque provides the collections/Deque standard library API.

Source
# Deque provides the collections/Deque standard library API.
class Deque
  # Deque.items stores instance state.
  # @type Array
  items: []

  # Deque.initialize provides the collections/Deque 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())

  # Deque.clear provides the collections/Deque standard library operation.
  # @return Nil the resulting value.
  clear: ->
    self.items = []
    self

  # Deque.empty? provides the collections/Deque standard library operation.
  # @return Boolean whether the condition is true.
  empty?: ->
    self.items.empty?()

  # Deque.from_array provides the collections/Deque standard library operation.
  # @param values Array values value.
  # @return Array the resulting value.
  from_array: values ->
    Deque(values)

  # Deque.len provides the collections/Deque standard library operation.
  # @return Int the resulting value.
  len: ->
    self.items.len()

  # Deque.new provides the collections/Deque standard library operation.
  # @return Self the resulting value.
  new: ->
    Deque(nil)

  # Deque.peek_back provides the collections/Deque standard library operation.
  # @return Any the resulting value.
  peek_back: ->
    if self.empty?()
      raise error("collections.Deque.peek_back: empty deque")
    self.items[self.items.len() - 1]

  # Deque.peek_front provides the collections/Deque standard library operation.
  # @return Any the resulting value.
  peek_front: ->
    if self.empty?()
      raise error("collections.Deque.peek_front: empty deque")
    self.items[0]

  # Deque.pop_back provides the collections/Deque standard library operation.
  # @return Any the resulting value.
  pop_back: ->
    if self.empty?()
      raise error("collections.Deque.pop_back: empty deque")
    self.items.pop()

  # Deque.pop_front provides the collections/Deque standard library operation.
  # @return Any the resulting value.
  pop_front: ->
    if self.empty?()
      raise error("collections.Deque.pop_front: empty deque")
    value = self.items[0]
    self.items = self.items.slice(1, self.items.len())
    value

  # Deque.push_back provides the collections/Deque standard library operation.
  # @param value String value value.
  # @return Any the resulting value.
  push_back: value ->
    self.items.push(value)
    self

  # Deque.push_front provides the collections/Deque standard library operation.
  # @param value String value value.
  # @return Any the resulting value.
  push_front: value ->
    next = [value]
    i = 0
    while i < self.items.len()
      next.push(self.items[i])
      i = i + 1
    self.items = next
    self

  # Deque.to_array provides the collections/Deque standard library operation.
  # @return Array the resulting value.
  to_array: ->
    self.items.slice(0, self.items.len())

Instance Variables

items

Deque.items

lib/collections/deque.tya:5

Deque.items stores instance state.

Source
  # Deque.items stores instance state.
  # @type Array
  items: []

Methods

clear

Deque.clear()

lib/collections/deque.tya:18

Deque.clear provides the collections/Deque standard library operation.

Source
  # Deque.clear provides the collections/Deque standard library operation.
  # @return Nil the resulting value.
  clear: ->
    self.items = []
    self

empty?

Deque.empty?()

lib/collections/deque.tya:24

Deque.empty? provides the collections/Deque standard library operation.

Source
  # Deque.empty? provides the collections/Deque standard library operation.
  # @return Boolean whether the condition is true.
  empty?: ->
    self.items.empty?()

from_array

Deque.from_array(values)

lib/collections/deque.tya:30

Deque.from_array provides the collections/Deque standard library operation.

Source
  # Deque.from_array provides the collections/Deque standard library operation.
  # @param values Array values value.
  # @return Array the resulting value.
  from_array: values ->
    Deque(values)

initialize

Deque.initialize(values = nil)

lib/collections/deque.tya:10

Deque.initialize provides the collections/Deque standard library operation.

Source
  # Deque.initialize provides the collections/Deque 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

Deque.len()

lib/collections/deque.tya:35

Deque.len provides the collections/Deque standard library operation.

Source
  # Deque.len provides the collections/Deque standard library operation.
  # @return Int the resulting value.
  len: ->
    self.items.len()

new

Deque.new()

lib/collections/deque.tya:40

Deque.new provides the collections/Deque standard library operation.

Source
  # Deque.new provides the collections/Deque standard library operation.
  # @return Self the resulting value.
  new: ->
    Deque(nil)

peek_back

Deque.peek_back()

lib/collections/deque.tya:45

Deque.peek_back provides the collections/Deque standard library operation.

Source
  # Deque.peek_back provides the collections/Deque standard library operation.
  # @return Any the resulting value.
  peek_back: ->
    if self.empty?()
      raise error("collections.Deque.peek_back: empty deque")
    self.items[self.items.len() - 1]

peek_front

Deque.peek_front()

lib/collections/deque.tya:52

Deque.peek_front provides the collections/Deque standard library operation.

Source
  # Deque.peek_front provides the collections/Deque standard library operation.
  # @return Any the resulting value.
  peek_front: ->
    if self.empty?()
      raise error("collections.Deque.peek_front: empty deque")
    self.items[0]

pop_back

Deque.pop_back()

lib/collections/deque.tya:59

Deque.pop_back provides the collections/Deque standard library operation.

Source
  # Deque.pop_back provides the collections/Deque standard library operation.
  # @return Any the resulting value.
  pop_back: ->
    if self.empty?()
      raise error("collections.Deque.pop_back: empty deque")
    self.items.pop()

pop_front

Deque.pop_front()

lib/collections/deque.tya:66

Deque.pop_front provides the collections/Deque standard library operation.

Source
  # Deque.pop_front provides the collections/Deque standard library operation.
  # @return Any the resulting value.
  pop_front: ->
    if self.empty?()
      raise error("collections.Deque.pop_front: empty deque")
    value = self.items[0]
    self.items = self.items.slice(1, self.items.len())
    value

push_back

Deque.push_back(value)

lib/collections/deque.tya:76

Deque.push_back provides the collections/Deque standard library operation.

Source
  # Deque.push_back provides the collections/Deque standard library operation.
  # @param value String value value.
  # @return Any the resulting value.
  push_back: value ->
    self.items.push(value)
    self

push_front

Deque.push_front(value)

lib/collections/deque.tya:83

Deque.push_front provides the collections/Deque standard library operation.

Source
  # Deque.push_front provides the collections/Deque standard library operation.
  # @param value String value value.
  # @return Any the resulting value.
  push_front: value ->
    next = [value]
    i = 0
    while i < self.items.len()
      next.push(self.items[i])
      i = i + 1
    self.items = next
    self

to_array

Deque.to_array()

lib/collections/deque.tya:94

Deque.to_array provides the collections/Deque standard library operation.

Source
  # Deque.to_array provides the collections/Deque standard library operation.
  # @return Array the resulting value.
  to_array: ->
    self.items.slice(0, self.items.len())