Return-Path: Delivered-To: apmail-incubator-couchdb-dev-archive@locus.apache.org Received: (qmail 47202 invoked from network); 14 Oct 2008 10:09:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 14 Oct 2008 10:09:56 -0000 Received: (qmail 32975 invoked by uid 500); 14 Oct 2008 10:09:56 -0000 Delivered-To: apmail-incubator-couchdb-dev-archive@incubator.apache.org Received: (qmail 32930 invoked by uid 500); 14 Oct 2008 10:09:55 -0000 Mailing-List: contact couchdb-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-dev@incubator.apache.org Delivered-To: mailing list couchdb-dev@incubator.apache.org Received: (qmail 32919 invoked by uid 99); 14 Oct 2008 10:09:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Oct 2008 03:09:55 -0700 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [83.97.50.139] (HELO jan.prima.de) (83.97.50.139) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Oct 2008 10:08:49 +0000 Received: from [10.0.1.6] (e178226144.adsl.alicedsl.de [::ffff:85.178.226.144]) (AUTH: LOGIN jan, TLS: TLSv1/SSLv3,128bits,AES128-SHA) by jan.prima.de with esmtp; Tue, 14 Oct 2008 10:03:24 +0000 Message-Id: From: Jan Lehnardt To: couchdb-dev@incubator.apache.org In-Reply-To: <21a10fe00810140236l2ac17e31v26740d5f4bb4cb10@mail.gmail.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v928.1) Subject: Re: Not a big deal, but is the emit function really necessary? Date: Tue, 14 Oct 2008 12:02:53 +0200 References: <21a10fe00810140236l2ac17e31v26740d5f4bb4cb10@mail.gmail.com> X-Mailer: Apple Mail (2.928.1) X-Virus-Checked: Checked by ClamAV on apache.org On Oct 14, 2008, at 11:36 , John Beppu wrote: > While working on a map function, it occurred to me that instead of > emit(key, > doc) what if I could just return [ [key, doc], ... ]. > > Again, not a big deal. I just thought it would be more concise. I think it makes for cleaner code when there are explicit calls to `emit()` instead of having to build up a magic data structure that later can get returned. function(doc) { if(!doc.stuff) { return; } for(var idx in doc.stuff) { emit(doc.stuff, 1); } } vs. function(doc) { if(!doc.stuff) { return; } var return_val = [] for(var idx in doc.stuff) { return_val.push([doc.stuff[idx], 1]); } return return_val; } `emit()` is nothing but an alias to Array.push() internally: emit = function(key, value) { map_results.push([key, value]); } (from share/server/main.js) Cheers Jan --