Project

General

Profile

Feature #16987

Updated by sawa (Tsuyoshi Sawada) over 4 years ago

Enumerations are designed Context: Early in Ruby's life, it was made a design decisions for our enumerations to be greedy (immediately executed on each method call within a chain) by default. Sometimes, that chaining). Sometimes it is not useful for practical purposes (e.g. 2 mln 2mln strings array, array -- drop comments, split into fields, find the first ten 10 whose field 2 is equal to some value). So search value), so one needs either resorts to either do non-idiomatic "do everything in one `each` block, block", or use to `Enumerable#lazy`. There are three problems with the latter: 

 
 1. It is much less known, known 
 2. It is said to be _almost always_ slower slow than non-lazy, and therefore not recommended, recommended 
 3. It lacks some methods that are often necessary in processing large data chunks. 

 I want to discuss (3) here. Examples of methods `Enumerator::Lazy` would better, but actually don't, have methods such as: don't have: `#flatten`, `#product`, and `#compact`. They are One might notice it all methods of the Array, not Enumerable. In fact, 
 
 Enumerable, but  
 1. They probably they _should_ belong to be present in `Enumerable` (none of them requires require anything besides `#each` to function), function) 
 2. They they are definitely useful for to lazily processing process large sequences.

Back