Created
September 18, 2016 06:21
-
-
Save you-ssk/c76e9b507d30bc83442fb18e7989beda 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
def empty?(e) | |
e.peek | |
false | |
rescue | |
true | |
end | |
def merge(*src) | |
src = src.map{|s| s.to_enum} | |
while true | |
src = src.delete_if{|s| empty?(s)} | |
return if src.empty? | |
it = src.min_by {|e| e.peek.to_i} | |
yield(it.next.to_i) | |
end | |
end | |
if __FILE__ == $0 | |
merge(File.open('aaa'), File.open('bbb')){|x| p x} | |
merge(File.open('aaa'), [2,5,11,12,13,90]){|x| p x} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment