tag:blogger.com,1999:blog-165807313160822069.post2988983860826015578..comments2024-01-22T04:01:01.636-05:00Comments on Ubuntu: A Love/Hate Relationship: ReduceRob Brittonhttp://www.blogger.com/profile/06467713562648469830noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-165807313160822069.post-59538002233151379582008-06-01T11:15:00.000-04:002008-06-01T11:15:00.000-04:00Zip is handy, although I've never used it in Ruby ...Zip is handy, although I've never used it in Ruby (my experience with it was only in Haskell). Although a quick peek at the Ruby docs gives you enough info. In fact you don't even need to put .each there, as zip can receive a block as well and does the exact same thing.<BR/><BR/>What zip does is it packages 1 or more lists into a list of arrays, where each element of the result is an array containing the corresponding elements of in that position of the parameter lists. In Ruby if you pass a block to zip, then instead of returning an array it applies the block to the group of elements.<BR/><BR/>If the lists have a different size, I believe it is implementation dependent on what happens. Ruby returns a list with the same size as the longest list, with the elements of the shorter lists being nil. Haskell returns a list with the length of the shorter list, and discards the other data. So I'm not sure.Rob Brittonhttps://www.blogger.com/profile/06467713562648469830noreply@blogger.comtag:blogger.com,1999:blog-165807313160822069.post-24390832087546480142008-05-31T11:35:00.000-04:002008-05-31T11:35:00.000-04:00I love Enumerable#inject and only after reading th...I love Enumerable#inject and only after reading this did I remember that it’s also called reduce in other parlance. Thanks Rob!<BR/><BR/>Hey, can I make a request? Cover Enumerable#zip and its equivalents. I realized the other day how useful this thing was and how the name finally makes sense to me while I was comparing files in two different directories by doing something like<BR/><BR/>Dir['something/*'].zip(Dir['something_else/*']).each {|first, second| puts `cmp #{first} #{second}` }Edwardhttps://www.blogger.com/profile/02735774643059703278noreply@blogger.com