Module: Lab419::Enumerable::Pair

Extended by:
Pair
Included in:
Pair
Defined in:
lib/lab419/core/enumerable/pair.rb

Instance Method Summary collapse

Instance Method Details

#pairs(enum, options = {}, &blk) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/lab419/core/enumerable/pair.rb', line 5

def pairs enum, options={}, &blk
  enum.each_with_index do | e1, i1 |
    enum.each_with_index do | e2, i2 |
      next if i2 < i1  || i2 == i1 && !options[:reflexive]
      blk.( [e1, e2 ] )
    end
  end
end

#pairs_with_rest(enum, options = {}, &blk) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/lab419/core/enumerable/pair.rb', line 13

def pairs_with_rest enum, options={}, &blk
  x = enum.to_a
  enum.each_with_index do | e1, i1 |
    enum.each_with_index do | e2, i2 |
      next if i2 < i1  || i2 == i1 && !options[:reflexive]
      blk.( [[e1, e2 ], x.without_indices(i1,i2)] )
    end
  end
end