Sha256: 9c4ba6576144e5e9d816b34881a984200536dd0b6c10bc2f06ce0c58f71065e1

Contents?: true

Size: 532 Bytes

Versions: 30

Compression:

Stored size: 532 Bytes

Contents

module Pairs
  private
  def pair(first, second)
    Pair.new(first, second)
  end
end

class Pair
  include Comparable

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

  def first
    @first.()
  end

  def second
    @second.()
  end

  def enumerator
    Enumerator.new { |y|
      y << first
      y << second
      raise StopIteration.new
    }
  end

  def <=>(other)
    (first <=> other.first) <=> (second <=> other.second)
  end

  def to_s
    "(#{first}, #{second})"
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
totally_lazy-0.1.54 lib/totally_lazy/pair.rb
totally_lazy-0.1.53 lib/totally_lazy/pair.rb
totally_lazy-0.1.52 lib/totally_lazy/pair.rb
totally_lazy-0.1.51 lib/totally_lazy/pair.rb
totally_lazy-0.1.50 lib/totally_lazy/pair.rb
totally_lazy-0.1.49 lib/totally_lazy/pair.rb
totally_lazy-0.1.48 lib/totally_lazy/pair.rb
totally_lazy-0.1.47 lib/totally_lazy/pair.rb
totally_lazy-0.1.46 lib/totally_lazy/pair.rb
totally_lazy-0.1.45 lib/totally_lazy/pair.rb
totally_lazy-0.1.44 lib/totally_lazy/pair.rb
totally_lazy-0.1.43 lib/totally_lazy/pair.rb
totally_lazy-0.1.42 lib/totally_lazy/pair.rb
totally_lazy-0.1.41 lib/totally_lazy/pair.rb
totally_lazy-0.1.39 lib/totally_lazy/pair.rb
totally_lazy-0.1.38 lib/totally_lazy/pair.rb
totally_lazy-0.1.37 lib/totally_lazy/pair.rb
totally_lazy-0.1.36 lib/totally_lazy/pair.rb
totally_lazy-0.1.35 lib/totally_lazy/pair.rb
totally_lazy-0.1.34 lib/totally_lazy/pair.rb