Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2BC599638 for ; Sun, 27 May 2012 15:33:38 +0000 (UTC) Received: (qmail 46444 invoked by uid 500); 27 May 2012 15:33:36 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 46358 invoked by uid 500); 27 May 2012 15:33:36 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 46350 invoked by uid 99); 27 May 2012 15:33:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 May 2012 15:33:36 +0000 X-ASF-Spam-Status: No, hits=4.7 required=5.0 tests=FREEMAIL_FORGED_REPLYTO,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [98.139.212.183] (HELO nm24.bullet.mail.bf1.yahoo.com) (98.139.212.183) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 27 May 2012 15:33:25 +0000 Received: from [98.139.212.150] by nm24.bullet.mail.bf1.yahoo.com with NNFMP; 27 May 2012 15:33:03 -0000 Received: from [98.139.212.223] by tm7.bullet.mail.bf1.yahoo.com with NNFMP; 27 May 2012 15:33:03 -0000 Received: from [127.0.0.1] by omp1032.mail.bf1.yahoo.com with NNFMP; 27 May 2012 15:33:03 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 707570.15121.bm@omp1032.mail.bf1.yahoo.com Received: (qmail 46382 invoked by uid 60001); 27 May 2012 15:33:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1338132783; bh=+pARk6uFzGCgLd4CtlbCAZcyaxLV+zE+cLulMEfoTg4=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=F7S3oaPBVpCV3BMsxj4dFsMLx7beo8K+TVcq3E1YRePEIhrYTJumjVyRC9+EaoZvRHMLaApyq94I/obYojpoHlxgwu8PlrTK3TVl6q26INBuzoCztiOEMRSOYpEcMaVZDhaGrS+PjbwmtCrAq2wjBqSYMhM5aKPdXNvmw1+3txM= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=27PMFracvXRfo4utpbVhxWNOoqRZ6N3X8vHuBbMdrLvyakECu7zG7iek/u4nyFqU1ZwE7xSoyUOL6Q8B35PeB+HOw/iuNpqgOqLtc1+cYt1Cd/pn/9zqS4tlUNFvpT+AzmXpvvPMj+/8B3ArcfjaxWzmv0pLGGqOnn0uMfUfEIk=; X-YMail-OSG: EpSYQYQVM1kWuVvP0ZlvnI6UdgJhZ8a1xIxnWM4ld796MIS KwP5me4_t1tRO25x9n3xfs7kdK3D.tZpX2XtUbUpaLbLyi3_HkRH_nsshs5A SizkvLNBiR.BDwdskpdDjk56eBy2Cnu77LcNE4xHESbldl9usgqk3ruD3VOt zj0EfNiH80FbQBR4Qo68nltkABuO1_tk3S.4a.xHtLkiw1914Je4XERvzU9q TjYaq7cYvrYaOOfhmjhNk8ATGoY1UN.MVJvjFkX.bNXlRyK2Rp7RlTeR9JAh ascmGQwlUx6nPGYr5LLQT8La_ComV5oAWSGfnzZ.daLFwus.gMd3XClgOmnT gNsB25JB.xhKhGB1MZCqZnrY2NSBPP58MSKAzeUNdKqlLRcMrfRsY6ro_17_ S4EpQtkk_m6L1R5oy5ILNT3TLWzaqhTvzDPybeuhdhtT39pGq.qxsMaYUjFt OcNuf92NO8iwfpezSzBx0C5uOV.g- Received: from [82.22.28.199] by web162801.mail.bf1.yahoo.com via HTTP; Sun, 27 May 2012 08:33:03 PDT X-Mailer: YahooMailWebService/0.8.118.349524 Message-ID: <1338132783.42011.YahooMailNeo@web162801.mail.bf1.yahoo.com> Date: Sun, 27 May 2012 08:33:03 -0700 (PDT) From: Jeremy Smith Reply-To: Jeremy Smith Subject: Erlang reduce functions To: "user@couchdb.apache.org" MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="2065536479-206349681-1338132783=:42011" --2065536479-206349681-1338132783=:42011 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hi,=0A=0AI am new to erlang, just started today, because we were advised to= move some of our views to native erlang views, I am trying to write a redu= ce function:=0A=0AThe Values its using seem to be in the form:=0A[[1, 1, 1,= 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],= [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1= , 1, 1, 1, 1, 1, 1, 1, 1]]=0A=0A=0Aso I have tried to do the following to g= et a count of all the 1's, but it only gives me the count of the outermost = lists (in the above case 3, instead of 60(ish))=0A=0AMy Reduce funtion:=0Af= un(Keys, Values, ReReduce) -> lists:flatlength(Values) end.=0A=0A=0AMy Map = function looks like this:=0Afun({Doc}) ->=0A=A0 =A0 Emitter =3D fun(Doc) ->= =0A=A0 =A0 =A0 =A0 Date =A0 =A0 =A0 =A0 =A0 =3D proplists:get_value(<<"publ= ish_date">>, =A0 Doc),=0A=0A=A0 =A0 =A0 =A0 Year =3D string:substr(erlang:b= itstring_to_list(Date), 1, 4),=0A=A0 =A0 =A0 =A0 Emit(erlang:list_to_bitstr= ing(Year), 1)=0A=A0 =A0 end,=0A=0A=A0 =A0 HasRequiredFields =3D fun(Doc) ->= =0A=A0 =A0 =A0 =A0 case {proplists:is_defined(<<"a_number">>, Doc), proplis= ts:is_defined(<<"publish">>, Doc), proplists:is_defined(<<"publish_date">>,= Doc)} of=0A=A0 =A0 =A0 =A0 =A0 =A0 {true, true, true} ->=0A=A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 Emitter(Doc);=0A=0A=A0 =A0 =A0 =A0 =A0 =A0 _->=0A=A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 false=0A=A0 =A0 =A0 =A0 end=0A=A0 =A0 end,=0A=0A=A0= =A0 HasRequiredFields(Doc)=0Aend.=0A=0ACheers=0AJeremy --2065536479-206349681-1338132783=:42011--