Top Level Namespace

Defined Under Namespace

Modules: Math, Stick Classes: Array, Exception, Numeric, String

Instance Method Summary collapse

Instance Method Details

#map(*enums) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/stick/mapcar.rb', line 38

def map(*enums)
  generators = []; enums.each { |e| generators << Generator.new(e) }
  while true
    begin
      params = []; generators.each { |g| g.current; params << g.next }
        rescue EOFError
      return
    end
    yield(*params)
  end
end

#mapcar(*enums) ⇒ Object

Non-recursive mapcar (works on all Enumerables)



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/stick/mapcar.rb', line 23

def mapcar(*enums)
  generators = enums.collect { |e| Generator.new(e) }
  result = []
  while true
    begin
      params = generators.collect { |g| g.current; g.next }
        rescue EOFError
      return result
    end
    result << yield(*params)
  end
end