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 01:11:07 +0100 Message-ID: <87egq95g10.fsf@petton.fr> References: <878uglwmra.fsf@petton.fr> <874mr9w8at.fsf@petton.fr> <87lhkkefhn.fsf@petton.fr> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1422835880 3312 80.91.229.3 (2 Feb 2015 00:11:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 2 Feb 2015 00:11:20 +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 01:11:19 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 1YI4bm-0000F9-Rg for ged-emacs-devel@m.gmane.org; Mon, 02 Feb 2015 01:11:18 +0100 Original-Received: from localhost ([::1]:52340 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YI4bl-0004Ds-P2 for ged-emacs-devel@m.gmane.org; Sun, 01 Feb 2015 19:11:17 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YI4bj-0004Dl-0k for emacs-devel@gnu.org; Sun, 01 Feb 2015 19:11:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YI4be-0008A7-1a for emacs-devel@gnu.org; Sun, 01 Feb 2015 19:11:14 -0500 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:37736) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YI4bd-0008A2-RM for emacs-devel@gnu.org; Sun, 01 Feb 2015 19:11:09 -0500 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 5F9CA207FE for ; Sun, 1 Feb 2015 19:11:09 -0500 (EST) Original-Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Sun, 01 Feb 2015 19:11:09 -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=92HtppDndZBVP0dEo/9m3HA+yr0=; b=La7AgoaCZ51fm/aYWuYR RrtxhH7HiJ7mOF2szzgc+5O1va597JTRLWadeEH9/OU3vZI6cpVCxlYja1qRnDT2 AcxsOVuGvOKMAs2JzLEl4X7jm4W/WdcI7+igkK+NQfGHDqy+rgq1C2plJiF/c0TW IyftkgshmIKkFq9/WDzpzVg= X-Sasl-enc: csm/WZ12EzEPb3Y2tbhHbvP5ERCuHjZ3TBdth9jNqj7Q 1422835868 Original-Received: from blueberry (unknown [213.89.134.104]) by mail.messagingengine.com (Postfix) with ESMTPA id 7E5CBC00295; Sun, 1 Feb 2015 19:11:08 -0500 (EST) User-agent: mu4e 0.9.9.6pre3; emacs 24.4.1 In-reply-to: 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:182222 Archived-At: 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? Nico -- Nicolas Petton http://nicolas-petton.fr