Sha256: 99888c523e33dd68c0d85d9f9f57aeff2bd2ec19ddd9a5170708cf80fb76d716

Contents?: true

Size: 571 Bytes

Versions: 2

Compression:

Stored size: 571 Bytes

Contents

require "forwardable"
require "hamster/stack"
require "hamster/read_copy_update"

module Hamster
  def self.mutable_stack(*items)
    MutableStack.new(stack(*items))
  end

  class MutableStack
    extend Forwardable
    include ReadCopyUpdate

    def push(item)
      transform { |stack| stack.push(item) }
    end
    def_delegator :self, :push, :<<
    def_delegator :self, :push, :enqueue

    def pop
      top = nil
      transform do |stack|
        top = stack.peek
        stack.pop
      end
      top
    end
    def_delegator :self, :pop, :dequeue
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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