From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicolas Petton Newsgroups: gmane.emacs.devel Subject: Re: Would seq-range and seq-mapcat be useful? Date: Mon, 02 Feb 2015 10:28:24 +0100 Message-ID: <87d25s64sn.fsf@petton.fr> References: <878uglwmra.fsf@petton.fr> <874mr9w8at.fsf@petton.fr> <87lhkkefhn.fsf@petton.fr> <87egq95g10.fsf@petton.fr> <8761bk3g87.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1422869316 19325 80.91.229.3 (2 Feb 2015 09:28:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 2 Feb 2015 09:28:36 +0000 (UTC) Cc: Nicolas Petton , Stefan Monnier , emacs-devel To: Oleh Krehel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Feb 02 10:28:35 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YIDJ5-00049O-9V for ged-emacs-devel@m.gmane.org; Mon, 02 Feb 2015 10:28:35 +0100 Original-Received: from localhost ([::1]:53661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIDJ4-0006c0-Jr for ged-emacs-devel@m.gmane.org; Mon, 02 Feb 2015 04:28:34 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39006) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIDJ1-0006bq-PM for emacs-devel@gnu.org; Mon, 02 Feb 2015 04:28:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YIDIx-0000cG-8A for emacs-devel@gnu.org; Mon, 02 Feb 2015 04:28:31 -0500 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:34081) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIDIx-0000c2-58 for emacs-devel@gnu.org; Mon, 02 Feb 2015 04:28:27 -0500 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id EC30B2086E for ; Mon, 2 Feb 2015 04:28:26 -0500 (EST) Original-Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Mon, 02 Feb 2015 04:28:26 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:references:from:to:cc:subject :in-reply-to:date:message-id:mime-version:content-type; s= smtpout; bh=+TCiGJUcNHCZQBU8J6G1r3QmBVc=; b=hh5BdM+SxLpdexgf147D 7d7F2RxCGRH8Uson+Ilp2woRY4rWW7A1udLxRNOJHNw21BUmKltT8MvXJc46TU/j yQEtgWpMO87Ha0He4WpVZEOMp5lo7opUgUTujlg9iFj0Ru/vd9IGU1+f5YzdgBAW Y49bOcPN7Ut5uMa0etVUOjA= X-Sasl-enc: WMwNfm7ASRt4yEtOVZMLqmGm+mE4+NxsPorjiG8eD1kN 1422869306 Original-Received: from blueberry (unknown [31.211.216.84]) by mail.messagingengine.com (Postfix) with ESMTPA id 144B6C00296; Mon, 2 Feb 2015 04:28:25 -0500 (EST) User-agent: mu4e 0.9.9.6pre3; emacs 24.4.1 In-reply-to: <8761bk3g87.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.111.4.27 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:182239 Archived-At: Oleh Krehel writes: > Nicolas Petton writes: > >> Oleh Krehel writes: >> >>> I'd like to have this: >>> >>> (defun seq-group-by (fn lst) >>> (nreverse >>> (cl-reduce >>> (lambda (acc it) >>> (let* ((key (funcall fn it)) >>> (cell (assoc key acc))) >>> (if cell >>> (setcdr cell (push it (cdr cell))) >>> (push (list key it) acc)) >>> acc)) >>> lst >>> :initial-value nil))) >>> >>> (seq-group-by >>> #'car >>> '(("a" 1) >>> ("b" 2) >>> ("b" 5) >>> ("c" 1))) >>> ;; (("a" ("a" 1)) >>> ;; ("b" ("b" 5) >>> ;; ("b" 2)) >>> ;; ("c" ("c" 1))) >>> (seq-group-by >>> #'cadr >>> '(("a" 1) >>> ("b" 2) >>> ("b" 5) >>> ("c" 1))) >>> ;; ((1 ("c" 1) >>> ;; ("a" 1)) >>> ;; (2 ("b" 2)) >>> ;; (5 ("b" 5))) >>> >>> Is this already somewhere? >> >> I don't think it is :) >> >> I think I'm going with the following 3 additions to seq.el: `seq-mapcat', >> `seq-group-by', and `seq-slice' (or `seq-partition'?). >> >> What do you think? >> > > I like `seq-group-by`. > > I'm not sure about `seq-mapcat`, since there is `cl-mapcan` (although > it's destructive), I guess `seq-mapcat` would be fine. > > And I would prefer the name `seq-partition` instead of `seq-slice`, > since `partition' is a Clojure name with same effect, and slice means > something different in Python. Yes, I felt the same. Nico -- Nicolas Petton http://nicolas-petton.fr