Editing Topic: RCR245 Project: RCR | RCRchive home

RCR 245: zip's broken metaphor

submitted by neoneye on Wed Apr 14 2004 03:19:56 AM -0700

Status: pending


Abstract

Enumerable#zip is good at making pairs. In a way that is intuitive and easy to grasp.

#zip is taking a block. Guess what happens.

(1..4).zip(1..4) {|a,b| a*b }

Problem

The problem is that nothing happens, the zip returns nil. It shows up that zip is commonly being used for multiway each! Thats a broken metaphor, which give people bad habits. See [] for discussion.

Proposal

I propose that zip concatenates and returns the result of the supplied block.

(4..6).zip(10..12) {|a,b| a*b } #=> [40, 55, 72]
%w(a b c).zip(1..9) {|i| i.reverse } #=> [[1, 'a'], [2, 'b'], [3, 'c']]

Analysis

incompatibility for people which has used zip for multiway each. However they should use callcc/enumerator instead of this bad habbit.

Implementation

don't know what to write.


Back to RCRchive.


RCR Submission page and RCRchive powered by Ruby, Apache, RuWiki (modified), and RubLog