Module: Enumerable

Defined in:
lib/rxraw-lineparser.rb

Overview

file: rxraw-lineparser.rb

Instance Method Summary collapse

Instance Method Details

#repeated_permutation(size, &blk) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rxraw-lineparser.rb', line 6

def repeated_permutation(size, &blk)
  f = proc do |memo, &blk|
    if memo.size == size
      blk.call memo
    else
      self.each do |i|
        f.call memo + [i], &blk
      end
    end
  end

  if block_given?
    f.call [], &blk
  else
    Enumerator.new(f, :call, [])
  end
end