DEV Community

Ashik Salman
Ashik Salman

Posted on

Ruby 2.7 adds Enumerator::Lazy#eager

Ruby 2.0 introduced Enumerator::Lazy, a special type of enumerator which helps us in processing chains of operations on a collection without actually executing it instantly.

By applying Enumerable#lazy method on any enumerable object, we can convert that object into Enumerator::Lazy object. The chains of actions on this lazy enumerator will be evaluated only when it is needed. It helps us in processing operations on large collections, files and infinite sequences seamlessly.

The Enumerable#eager method returns a normal enumerator from a lazy enumerator, so that lazy enumerator object can be passed to any methods which expects a normal enumerable object as an argument. Also, we can call other usual array methods on the collection to get desired results.

Full article: https://blog.bigbinary.com/2020/03/18/ruby-2-7-adds-enumerator-lazy-eager.html

Top comments (0)