On Sat, 10 Mar 2001, Yukihiro Matsumoto wrote: > In message "[ruby-talk:12330] Haskell goodies, RCR and challenge" > on 01/03/10, Robert Feldt <feldt / ce.chalmers.se> writes: > > | [0,2,4,6,8].all? {|e| e>=0} # => true > | [10,14,18].any? {|e| e%2 == 1} # => false > > I think it's good to add them to Enumerable. > > | [1,2,3,4].foldl(:+) # => 10 > > I like something like > > [1,2,3,4].foldl{|a,b|a+b} # => 10 > > There might be better name. > It works with all the following forms: # Different forms for foldl and foldr # [1,2,3,4].foldl(:+, 0) => 10 # [1,2,3,4].foldl(:+) => 10 # [1,2,3,4].foldl(0) {|a,b| a+b} => 10 # [1,2,3,4].foldl {|a,b| a+b} => 10 # [1,2,3,4].foldl(:+,0) {|a,b| a+b} => ArgumentError > | [1,2,3].scanl(0) {|a,b| a+b}) # => [0,1,3,6] > > Will Enumerable#inject do this job? > I thought inject was foldl?! > | [1,2,3,4].zip([10,20,30]) # => [[1,10],[2,20],[3,30]] > | [1,2,3].tail # => [2,3] > | [1,2,3,4].init # => [1,2,3] > > Behavior of these functions are not really apparent. I think we need > to discuss more about these. > They have been used in the functional programming community for years with these names (which doesnt mean we have to adopt them...). I'd say tail is a good name and a very useful method. 'init' is probably too close to 'initialize' so not good name. IMHO, 'zip' is a pretty good name (think about a zipper in your pants or jacket...) but I'm not sure the functionality is useful enough to promote it into the base lib. Regards, Robert