Skip to content

Instantly share code, notes, and snippets.

@AaronLasseigne
Last active August 29, 2015 13:56
Show Gist options
  • Save AaronLasseigne/9053030 to your computer and use it in GitHub Desktop.
Save AaronLasseigne/9053030 to your computer and use it in GitHub Desktop.
module Clojure
def self.repeat(x, n = nil)
[x].cycle(n)
end
def self.repeatedly(n = nil, &block)
i = n || Float::INFINITY
Enumerator.new(n) do |yielder|
while i > 0
yielder << block.call
i -= 1
end
end
end
def self.iterate(x, &block)
Enumerator.new do |yielder|
yielder << x
y = begin
x.dup
rescue TypeError
x
end
loop do
y = block.call(y)
yielder << y
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment