From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Oleh Krehel Newsgroups: gmane.emacs.devel Subject: Re: Would seq-range and seq-mapcat be useful? Date: Mon, 02 Feb 2015 08:49:44 +0100 Message-ID: <8761bk3g87.fsf@gmail.com> References: <878uglwmra.fsf@petton.fr> <874mr9w8at.fsf@petton.fr> <87lhkkefhn.fsf@petton.fr> <87egq95g10.fsf@petton.fr> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1422863627 25717 80.91.229.3 (2 Feb 2015 07:53:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 2 Feb 2015 07:53:47 +0000 (UTC) Cc: Stefan Monnier , emacs-devel To: Nicolas Petton Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Feb 02 08:53:46 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 1YIBpJ-0000cf-II for ged-emacs-devel@m.gmane.org; Mon, 02 Feb 2015 08:53:45 +0100 Original-Received: from localhost ([::1]:53388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIBpI-0004FF-RZ for ged-emacs-devel@m.gmane.org; Mon, 02 Feb 2015 02:53:44 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50229) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIBp6-0004Ew-1f for emacs-devel@gnu.org; Mon, 02 Feb 2015 02:53:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YIBoz-0006Nx-Mx for emacs-devel@gnu.org; Mon, 02 Feb 2015 02:53:31 -0500 Original-Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]:55539) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YIBoz-0006Nb-Gl for emacs-devel@gnu.org; Mon, 02 Feb 2015 02:53:25 -0500 Original-Received: by mail-wi0-f178.google.com with SMTP id bs8so13339729wib.5 for ; Sun, 01 Feb 2015 23:53:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=Uvcj3KxBO14MJRBuyxdvE02FvFloMyTOwhLqQhDio9g=; b=GDVS96i/JTGWJ//M8U6Qz8shh/rp8Xz96Pflcv4v7OJAbM6a06C0tE8KNW6zR5xrlT ap3rsehic1O8Hbqp7w0vTywdy1t9xdbT2mppOxdQpXh+a6KHfyFOuSwMM2a2KEkoJVf3 L1DadM/mRNfrqLL8aUE7vLu8YHdU7p61PXb2+cQTTzYzGUW6QA3gsPwLofSeemEGdC5H 9WtxESP0Pjvb7snHZJLrfaXQAW/H+6rpbnms7XftexSJuLPCRk9fOD4UVyO4PnlPNCHa 1srzRyviB6BKiLnTq7ekf7hLWcMdpcmZQHGkkfBkwvLErTMJpWiw5/D8mDJZL0Q1sA/F wwOQ== X-Received: by 10.181.11.136 with SMTP id ei8mr20993879wid.71.1422863604250; Sun, 01 Feb 2015 23:53:24 -0800 (PST) Original-Received: from firefly (dyn069045.nbw.tue.nl. [131.155.69.45]) by mx.google.com with ESMTPSA id pp10sm3327977wjc.31.2015.02.01.23.53.23 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 01 Feb 2015 23:53:23 -0800 (PST) In-Reply-To: <87egq95g10.fsf@petton.fr> (Nicolas Petton's message of "Mon, 02 Feb 2015 01:11:07 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::232 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:182234 Archived-At: 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. Oleh