« Return to Thread: Proposal: Array#walker

Re: Proposal: Array#walker

by Kornelius Kalnbach :: Rate this Message:

Reply to Author | View in Thread



Am 14.11.2007 um 01:37 schrieb Wolfgang Nádasi-Donner <ed.odanow@...
e>:

> Good morning all together!
>
> I know it is very late for Ruby 1.9.1 proposals, but I have a very  
> simple and easy suggestion. While writing a program to generate the  
> Ruby program for some guessUTF test (border cases which should not  
> success), I recognized, that it can be very helpful for several use  
> cases to have a method Array#walker with the following Ruby  
> implementation...
>
> class Array
>  def walker
>    l = self.length
>    l.times do |i|
>      yield self[0, i], self[i], self[i+1, l-i-1]
>    end
>  end
> end
>
> A simple usage example is...
>
> [1,2,3,4].walker{|pre,el,post|puts "#{pre.inspect}-#{el} - #
> {post.inspect}"}
>
> Output:
> []-1 - [2, 3, 4]
> [1]-2 - [3, 4]
> [1, 2]-3 - [4]
> [1, 2, 3]-4 - []
>
> What do you think about this (hopefully) minor change proposal?
>
> Wolfgang Nádasi-Donner
>
>

I think this is a very specialized method that should not go into the  
core library...

[murphy]

 « Return to Thread: Proposal: Array#walker