Sha256: 22027d27db89bca86c71bfca38b4caa3728e9f67e54e05db3abcf0517a972559

Contents?: true

Size: 611 Bytes

Versions: 3

Compression:

Stored size: 611 Bytes

Contents

module Pair

  def pair(first, second)
    Pair.new(first, second)
  end

  def from_map(a_map)
    Pair.from_map(a_map)
  end

  class Pair

    def initialize(first, second)
      @first = -> { first }
      @second = -> { second }
    end

    def first
      @first.call
    end
    alias key first

    def second
      @second.call
    end
    alias value second

    def to_map
      {first => second}
    end

    def self.from_map(a_map)
     sequence(a_map).map{|k,v| Pair.new(k,v)}
    end

    def to_s
      to_map.inspect
    end

    def values
      sequence(first, second)
    end

  end


end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
totally_lazy-0.0.3 lib/pair.rb
totally_lazy-0.0.2 lib/pair.rb
totally_lazy-0.0.1 lib/pair.rb