Sha256: f0633221bc0aa2cd3b4870040fd3bec2e26c8d02b9fb4d0e8065948bea11f081

Contents?: true

Size: 628 Bytes

Versions: 8

Compression:

Stored size: 628 Bytes

Contents

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

  def first
    ->(pair) { pair.first }
  end

  def second
    ->(pair) { pair.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

8 entries across 8 versions & 1 rubygems

Version Path
totally_lazy-0.1.62 lib/totally_lazy/pair.rb
totally_lazy-0.1.61 lib/totally_lazy/pair.rb
totally_lazy-0.1.60 lib/totally_lazy/pair.rb
totally_lazy-0.1.59 lib/totally_lazy/pair.rb
totally_lazy-0.1.58 lib/totally_lazy/pair.rb
totally_lazy-0.1.57 lib/totally_lazy/pair.rb
totally_lazy-0.1.56 lib/totally_lazy/pair.rb
totally_lazy-0.1.55 lib/totally_lazy/pair.rb