On May 2, 2007, at 8:57 AM, James Edward Gray II wrote: > On Apr 29, 2007, at 1:17 PM, Brad Ediger wrote: > >> # Maps n-at-a-time (n = arity of given block) and collects the >> results >> def mapn(&b) >> r = [] >> each_slice(b.arity) {|*args| r << b.call(*args) } >> r >> end > > That's pretty darn clever. You can collapse it to one line with > inject() of course: > > def mapn(&b) > enum_slice(b.arity).inject([]) {|r, args| r << b.call(*args) } > end Didn't even think about inject here. Awesome. I'm sure that I'm going to be using mapn more, as it's cool. I can't take credit for the mapn concept though: eachn is a Facets function I stumbled across. --be