Created
July 19, 2015 14:51
-
-
Save colinmarc/2e1a01ae875b0f68835b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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