From: Bernard Lambeau Date: 2011-07-14T17:23:59+09:00 Subject: Re: [ANN] summaryse 1.1.0 Released --20cf300512b21b5ad604a803419e Content-Type: text/plain; charset=ISO-8859-1 I understand your objections and must add that summaryse is somewhat unusual. However, a changelog is not a README... > Summaryse.register(:comma_join) do |ary| > > ary.join(', ') > > end > > [1, 4, 12, 7].summaryse(:comma_join) > > # => "1, 4, 12, 7" > > Personally I'd rather directly use #join - it's short as well and much > clearer what is happening - especially if #register and #summaryse > calls are in separate locations. > Of course, if you have the array directly. Maybe that array is far from your control due to lots of recursive calls that summaryse applies when summarizing complex relations. Have a look at README. > [ > > { :size => 12 }, > > { :size => 17 } > > ].summaryse(:size => :max, :hobbies => lambda{|a| a}) > > # => {:size => 17, :hobbies => []} > > I am not sure I understand what this is good for. Can you provide a > bit more insight? > Summaryse tries not to make any strong assumption about the heading of the summarized relations (relation = set of tuples ~= array of hashes). I don't want to throw an error in such case (recall from README that one of my main goals is to merge YAML files easily) and assuming an empty array is therefore sound. > * Added the ability to use objects responding to to_summaryse as > > aggregator > > functions: > > > > class Foo > > def to_summaryse; :sum; end > > end > > [1, 2, 3].summaryse(Foo.new) > > # => 6 > > Why would I want to do that? Wouldn't it be much shorter to just use > the constant? > Yes, of course, because this is a simple example (extracted from a changelog, even if I have to admit that the same example is in the readme). In certain cases is might be useful to provide complex and reusable summarization operators as named modules or classes. to_summaryse is done for that. > * Added the ability to explicitly bypass Hash entries as the result of a > > computation, by returning Summaryse::BYPASS > > > > [ > > { :hobbies => [:ruby], :size => 12 }, > > { :hobbies => [:music], :size => 17 } > > ].summaryse(:size => :max, :hobbies => lambda{|a| > > Summaryse::BYPASS}) > > # => {:size => 17} > > Hm... Same remark. > > Generally I would rather implement those directly. The reason is > simply that this will reduce component dependencies of my applications > by one. When weighting using an external component (e.g. a gem) vs. > doing it internally the benefit must be higher than the cost for me. > YMMV though. > I even encourage you to do so, especially in simplest cases. Merging complex YAML files is not a simple case. I've already implemented that in three projects, and would like to factorize that feature somewhere. An announce is just an announce. You're not required to find a gem useful ;-) Summaryse is an attempt to have a powerful summarization operator that supports relations in relations in relations, etc. It is a bit unusual, I confess, especially on special features like bypass and empty arrays... ok. Bernard > > Kind regards > > robert > > -- > remember.guy do |as, often| as.you_can - without end > http://blog.rubybestpractices.com/ > > -- PhD Student, Computer Science Department, EPL/INGI, UCLouvain, Belgium Mail: blambeau@gmail.com Mobile: +32 477 24 58 61 Blog: http://revision-zero.org/ Code: http://github.com/blambeau/ Follow: http://twitter.com/blambeau/ --20cf300512b21b5ad604a803419e--