From: Michael Guterl Date: 2007-02-28T11:17:05+09:00 Subject: Re: is there something method in ruby like python's reduce()? ------=_Part_17302_27416267.1172629022052 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 2/27/07, lnes wrote: > > there is python's build-in function reduce()'s definition > > ===================================================================== > reduce( function, sequence[, initializer]) > Apply function of two arguments cumulatively to the items of > sequence, from left to right, so as to reduce the sequence to a single > value. For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates > ((((1+2)+3)+4)+5). The left argument, x, is the accumulated value and > the right argument, y, is the update value from the sequence. If the > optional initializer is present, it is placed before the items of the > sequence in the calculation, and serves as a default when the sequence > is empty. If initializer is not given and sequence contains only one > item, the first item is returned. > ===================================================================== ri Enumerable#inject thanks. > > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_17302_27416267.1172629022052--