From: Robert Feldt Date: 2001-03-10T00:01:57+09:00 Subject: [ruby-talk:12330] Haskell goodies, RCR and challenge Hi, It's friday afternoon (here in Sweden that is) so here's a small script with goodies from Haskell (functional programming language) for Ruby: http://www.ce.chalmers.se/~feldt/ruby/extensions/funcprog/ Right now its only the powerful Haskell list functions added to Enumerable and Array but LazyArray (infinite sequences) is coming along (its working but requires changes to MetaRuby so I'll have to talk to Matju before including it...). Maybe its too much a feature bloat to add all of them to the built-in stuff but IMHO the following ones are very useful (and most have been previously discussed here on ruby-talk): [0,2,4,6,8].all? {|e| e>=0} # => true [10,14,18].any? {|e| e%2 == 1} # => false (0..4).to_a.partition {|e| e%2 == 0} # => [[0,2,4], [1,3]] [1,2,3,4].foldl(:+) # => 10 [1,2,3].scanl(0) {|a,b| a+b}) # => [0,1,3,6] [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] and have'nt you all dreamt of doing quicksort as: def qsort(a) a[0]?(l,h=a.tail.partition{|e|e