Sha256: cff62f43fc7ca45f179b71263394df43f56e22b9c669a64f31bdd06b45eb77d1

Contents?: true

Size: 548 Bytes

Versions: 2

Compression:

Stored size: 548 Bytes

Contents

require "forwardable"
require "hamster/queue"
require "hamster/read_copy_update"

module Hamster
  def self.mutable_queue(*items)
    MutableQueue.new(queue(*items))
  end

  class MutableQueue
    extend Forwardable
    include ReadCopyUpdate

    def enqueue(item)
      transform { |queue| queue.enqueue(item) }
    end
    def_delegate :self, :enqueue, :<<
    def_delegate :self, :enqueue, :add

    def dequeue
      head = nil
      transform do |queue|
        head = queue.head
        queue.dequeue
      end
      head
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hamster-1.0.1.pre.rc2 lib/hamster/experimental/mutable_queue.rb
hamster-1.0.1.pre.rc.1 lib/hamster/experimental/mutable_queue.rb