From: Robert Klemme Date: 2009-06-16T15:10:11+09:00 Subject: Re: each by arity On 15.06.2009 20:17, Yossef Mendelssohn wrote: > [Note: parts of this message were removed to make it a legal post.] > > On Sun, Jun 14, 2009 at 11:22 PM, trans wrote: >> Slice by arity seems pretty clear to me. Moreover, where is >> #map_slice? It starts to look a lot clearer when we think of adding >> "_slice" to every Enumerable method. > > Why is map_slice needed? What's the problem with calling each_slice and then > map on the result? Is it a case of optimization? Are you worried about the > resources you'll be using? If so, it's quite possible to use each_slice to > iterate over one collection while appending results to an array. But maybe > it's not functional enough for you. Or core enough. > > Go ahead and call out the Enumerator now. > > I have no trouble with requiring 'enumerator' and explicitly using exactly > the methods I want. I'd rather be clear than clever. Question is whether it is clever to duplicate all methods with another one that has "_slice" appended to the name. I personally favor the approach with Enumerator, e.g. depending on version enum.enum_for(:each_slice, 2).map {|a,b| ...} enum.each_slice(2).map {|a,b| ...} - especially since it works as easy for #each_cons and others. In other words: this is much more modular. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/