Class: Immutable::OutputRestrictedDeque

Inherits:
Queue
  • Object
show all
Includes:
Consable
Defined in:
lib/immutable/output_restricted_deque.rb

Overview

Immutable::OutputRestrictedDeque is an implementation of output-restricted deques described in “Purely Functional Data Structures” by Chris Okasaki.

Instance Method Summary collapse

Methods included from Consable

#+, #drop, #drop_while, #filter, #flat_map, #flatten, included, #intercalate, #intersperse, #map, #rev_map, #reverse, #subsequences, #take, #take_while, #transpose, #unshift, #zip, #zip_with

Methods included from Headable

#==, #[], #each, #each_index, #empty?, #eql?, #fetch, #find, #first, #foldl, #foldl1, #foldr, #foldr1, #hash, #head, #index, #inspect, #null?, #rindex, #shift, #tail, #to_list

Methods included from Foldable

#foldl, #length, #product, #sum

Methods inherited from Queue

[], empty, #empty?, #head, #initialize, #snoc, #tail

Constructor Details

This class inherits a constructor from Immutable::Queue

Instance Method Details

#cons(x) ⇒ Queue Also known as: prepend

Adds a new element at the head of self.

Parameters:

  • x (Object)

    the element to add.

Returns:

  • (Queue)

    a new queue.



14
15
16
17
# File 'lib/immutable/output_restricted_deque.rb', line 14

def cons(x)
  self.class.new(Stream.cons(->{x}, ->{@front}), @rear,
                 Stream.cons(->{x}, ->{@schedule}))
end