Method: Enumerable#partitions

Defined in:
lib/nose/util.rb

#partitions(max_length = nil) ⇒ Enumerator

Enumerate all partitionings of an enumerable

Returns:

  • (Enumerator)


25
26
27
28
29
30
31
32
# File 'lib/nose/util.rb', line 25

def partitions(max_length = nil)
  max_length = length if max_length.nil?
  Enumerator.new do |enum|
    1.upto(max_length).map do |length|
      enum.yield partition.with_index { |_, i| i < length }
    end
  end
end