From: Benoit Daloze Date: 2012-03-17T22:35:34+09:00 Subject: [ruby-core:43368] [ruby-trunk - Bug #6158] Enumerator::Lazy#take: should it be lazy? Issue #6158 has been updated by Benoit Daloze. matz: > use #first. map! etc. do not conform other bang method naming convention. Thank you for taking the decision. Shugo: I understand the use, so I also think it's worth having some form of lazy #take. However, I think many would expect #take to be eager, so it should be very well documented in the Enumerator::Lazy class documentation (with an example of #take and #first). Thomas Sawyer: > Both "takes" on this seem valid. You just made my day. > Could there be a special method similar to take for de-lazying and taking a segment of the enumeration? e.g. maybe #pinch ? Sounds interesting, could you open a new issue? Innokenty Mikhailov: > However I'm thinking about more radical solution: having methods with bang (!) always evaluate. I like it, it reminds me of #force, the alias of #to_a. And it has some notion of "I want it now, please evaluate the result". But as matz said, the naming convention is not respected, and defining all these methods simply to avoid an explicit method call is probably not worth it. ---------------------------------------- Bug #6158: Enumerator::Lazy#take: should it be lazy? https://bugs.ruby-lang.org/issues/6158#change-24675 Author: Benoit Daloze Status: Assigned Priority: Normal Assignee: Shugo Maeda Category: Target version: ruby -v: ruby 2.0.0dev (2012-03-15 trunk 35042) [x86_64-darwin10.8.0] Hello, I noticed #take is now defined on Enumerator::Lazy, and it has lazy behavior: (1..1000).lazy.select(&:even?).take 3 # => # I would expect #take to not be lazy and always produce an Array, like the original Enumerable#take does. I think many rubyists would expect that too. Do you have a use case for a lazy #take ? I can't find one right now. I've seen #6152, although I can't read it. I think `lazy.take(5)` should be equal to `lazy.first(5)` and it reads better. -- http://bugs.ruby-lang.org/