From: Yusuke Endoh <mame@...> Date: 2012-07-24T23:29:30+09:00 Subject: [ruby-core:46730] Re: [ruby-trunk - Feature #6636][Open] Enumerable#size Hello Marc-Andre 2012/7/24, marcandre (Marc-Andre Lafortune) <ruby-core@marc-andre.ca>: >> * Enumerator.new(size) is not acceptable because of compatibility: >> >> p Enumerator.new([1,2,3]).take(2) #=> [1, 2] > > Agreed. > I am proposing `Enumerator.new(size_lambda){ block }`, i.e. only if a block > is given, then the first argument can be a lambda/proc that can lazily > compute the size. This is just my guess, but matz will not like such a method whose meaning of its argument varies depending on whether block is given or not. > The old syntax of `Enumerator.new` without a block does not change meaning. Is it okay that there is no way to specify size in this case? >> * We cannot determine the size of enumerator when creating it: >> >> a = [1] >> e = a.permutation >> a << 2 >> p e.to_a #=> [[1, 2], [2, 1]] >> >> So, the API may need to receive a code fragment that calculates >> size, such as a Proc. > > Agreed. > This is why I propose that `to_enum` accepts a block that can calculate the > size, and Enumerator.new with a block can accept a lambda/proc for the > same. What argument(s) will the lambda/proc receive? -- Yusuke Endoh <mame@tsg.ne.jp>