yajl-ruby
yajl-ruby copied to clipboard
Allow encoding of Lazy Enumerable collections (Ruby 2.0)
trafficstars
Consider the following:
z = [{"x" => 5}, 2, 3].lazy.map{ |i| i}
#=> #<Enumerator::Lazy: #<Enumerator::Lazy: [{"x"=>5}, 2, 3]>:map>
z.first
#=> {"x"=>5}
Encoding hash z returns the following unexpected chunk:
=> ""#Enumerator::Lazy:0x00000001cb0448""
encoder = Yajl::Encoder.new
encoder.encode(z) do |chunk|
if chunk.nil? # got our terminator, encoding is done
close_connection_after_writing
else
puts chunk
end
end
It seems to me that one of the potential advantages of yajl is I could avoid using to_a on large lists to save memory.
This would be very nice.