I have two long streams of numbers coming from two different sources (binary data) in Ruby (1.9.2).
Two sources are encapsulated as two Enumerators .
I want to check that the two threads are exactly equal.
I came up with several solutions, but both of them seem rather inelegant.
The first just converts both to an array:
def equal_streams?(s1, s2) s1.to_a == s2.to_a end
This works, but it is not very efficient in terms of memory, especially if the streams contain a lot of information.
Another option is ... tg.
def equal_streams?(s1, s2) s1.each do |e1| begin e2 = s2.next return false unless e1 == e2
So, is there an easier and more elegant way to do this?
ruby enumerator
kikito
source share