Skip to content

Instantly share code, notes, and snippets.

@colinmarc
Created July 19, 2015 14:51
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 colinmarc/2e1a01ae875b0f68835b to your computer and use it in GitHub Desktop.
Save colinmarc/2e1a01ae875b0f68835b to your computer and use it in GitHub Desktop.
class Flatten(T)
include Iterator(T)
def initialize(@iterator : Iterator(Iterator(T)))
@current = @iterator.next
end
def next_
if (current = @current).is_a?(Iterator::Stop)
stop
else
next_val = current.next
if next_val.is_a?(Iterator::Stop)
@current = @iterator.next
next_
else
next_val
end
end
end
def next
next_
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment