Module: Abstractivator::Collections

Defined in:
lib/abstractivator/collections.rb

Instance Method Summary collapse

Instance Method Details

#multizip(enumerables, pad_value = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/abstractivator/collections.rb', line 3

def multizip(enumerables, pad_value=nil)
  es = enumerables.map(&:each)
  result = []
  fail_count = 0
  while fail_count < es.size do
    fail_count = 0
    heads = es.map do |e|
      begin
        e.next
      rescue StopIteration
        fail_count += 1
        pad_value
      end
    end
    result << heads if fail_count < es.size
  end
  result
end