From: matz@... (Yukihiro Matsumoto) Date: 2001-03-10T14:41:50+09:00 Subject: [ruby-talk:12374] Re: Haskell goodies, RCR and challenge Hi, In message "[ruby-talk:12330] Haskell goodies, RCR and challenge" on 01/03/10, Robert Feldt 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. | (0..4).to_a.partition {|e| e%2 == 0} # => [[0,2,4], [1,3]] I like this function. Although it's mere combination of "select" and "reject". But I don't prefer the word "partition" for the functionality. | [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. | [1,2,3].scanl(0) {|a,b| a+b}) # => [0,1,3,6] Will Enumerable#inject do this job? | [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. matz.