Sha256: c4f194ac5071aac922f3feab9077a4437fcf74f7cb07eaa330b17c4c73bf7338

Contents?: true

Size: 575 Bytes

Versions: 15

Compression:

Stored size: 575 Bytes

Contents

module Pair

  def pair(first, second)
    Pair.new(first, second)
  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

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
totally_lazy-0.1.22 lib/pair.rb
totally_lazy-0.1.21 lib/pair.rb
totally_lazy-0.1.20 lib/pair.rb
totally_lazy-0.1.19 lib/pair.rb
totally_lazy-0.1.18 lib/pair.rb
totally_lazy-0.1.17 lib/pair.rb
totally_lazy-0.1.16 lib/pair.rb
totally_lazy-0.1.15 lib/pair.rb
totally_lazy-0.1.14 lib/pair.rb
totally_lazy-0.1.13 lib/pair.rb
totally_lazy-0.1.12 lib/pair.rb
totally_lazy-0.1.11 lib/pair.rb
totally_lazy-0.1.10 lib/pair.rb
totally_lazy-0.1.9 lib/pair.rb
totally_lazy-0.1.0 lib/pair.rb