From: Robert Dober Date: 2009-04-19T18:19:20+09:00 Subject: Re: [ANN] Junctions for Ruby1.9 (Lab419::functional-0.1.2) On Sat, Apr 18, 2009 at 11:38 PM, Denis Defreyne wrote: > On Apr 17, 2009, at 11:17 PM, Robert Dober wrote: > >> E.g. >> >>  any(1, 2, 3) > 2     --> true >>  [ 1, 3, 5 ].all.odd? --> true >>  none( 1 ).zero?      --> true >>  all() == nil         --> true >>  any() == nil         --> false > > The examples you gave are equivalent to > >        [ 1, 2, 3 ].any? { |e| e > 2 } >        [ 1, 3, 5 ].all? { |e| e.odd? } >        ![ 1 ].any? { |e| e.zero? } >        [].all? { |e| e == nil } >        [].any? { |e| e == nil } > > What advantages does junctions in Ruby provide over #any? and #all? ? They are an abstraction of the code blocks, if you look at streams, the second concept implemented in Lab419::functional we have exactly the same pattern, delay is nothing more than a lambda. As a matter of fact the main pleasure I have got from releasing code in Ruby is that Ruby does all the work and I can get the compliments, well I cannot because you have pointed out that I have not done anything. Thank you very much ;) ok seriously now: I believe that this kind of abstraction is useful, makes code shorter and even more readable. Is it worth a package? Well maybe not, but what are you going to tell a perl6 guru if he asks you if Ruby got Junctions? (Proud in Ruby was indeed a key motivation, maybe that is bad, I dunno ) Look at this example: if a_set.any > b_set.all then would be if a_set.any?{ | x | b_set.all?{ | y | x > y } } then I kind of prefer to maintain code written in the first style. Cheers Robert