Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Ruby is beautiful

Name: Anonymous 2009-08-26 15:25

class Cycle
    def cycle(*args)
      args[((@_cycles ||= Hash.new(-1))[args.hash] += 1) % args.size]
    end
end

More beautiful code plees?

Name: Anonymous 2012-01-27 0:46

And now with no mutations!


function cycle(...)
  local array = {...}
  local length = table.getn(array)
  local loop
  loop = function(index)
    coroutine.yield(array[index])
    if index < length then
      return loop(index + 1)
    else
      return loop(1)
    end
  end
  return coroutine.wrap(function()
    loop(1)
  end)
end

for v in cycle('yaba', 'daba', 'doo') do
  print(v)
end

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List