From: Mathieu Bouchard Date: 2000-06-06T06:14:30-04:00 Subject: [ruby-talk:03118] Re: Min and max? > Well, there's at least one point to consider with the Kernel version. Kernel > is maybe not the right place for min since not all classes have meaningful > comparisons. So maybe Comparable is the place (or maybe not). I fully agree that Comparable is the right place for that. (I notice I have an old version that doesn't support those min/max... time to upgrade) Totally unrelated, I propose a new operation called "accum" in Enumeration: [2,7,3,23,78,1,2].accum {|a,b| a.max(b)} would return 78, the greatest element, for instance. precondition: there is at least one element, in which case the (degenerate) result is the element itself. an alternate version is to provide separately with a "base" (or "seed") value, typically the neutral element of the operation if it exists; in that case an empty array returns the "base" value. more examples: * summing the elements in an array * multiplying them * alternating sums (using substraction as the operation) * factorial * logic: "for all ... in ... such that ..." * logic: "exists ... in ... such that ..." * compute parity, hamming code * one-line reimplementations of "max", "min", "member?" * very inefficient reimplementations of "join", "collect", "select", "reject" * verifying a sort so as you see it's a very general function with a lot of uses. Mathieu Bouchard