Skip to content

Instantly share code, notes, and snippets.

@rares
Created November 3, 2011 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rares/1336540 to your computer and use it in GitHub Desktop.
Save rares/1336540 to your computer and use it in GitHub Desktop.
class Stream
attr_accessor :head
def initialize(head, &tail)
@head, @tail = head, tail
end
def tail
@tail ? @tail.call : nil
end
def take(i)
results, list = [], self
i.times { results << list.head; list = list.tail }
results
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment