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: Fri, 30 Jan 2015 17:23:23 +0100 Message-ID: <87386sdypw.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 1422635029 28082 80.91.229.3 (30 Jan 2015 16:23:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 30 Jan 2015 16:23:49 +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 Fri Jan 30 17:23:45 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 1YHEMA-0001f3-Hs for ged-emacs-devel@m.gmane.org; Fri, 30 Jan 2015 17:23:42 +0100 Original-Received: from localhost ([::1]:37588 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHEM9-0002jP-VA for ged-emacs-devel@m.gmane.org; Fri, 30 Jan 2015 11:23:41 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHELw-0002jJ-Kp for emacs-devel@gnu.org; Fri, 30 Jan 2015 11:23:29 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YHELt-0002ja-Eo for emacs-devel@gnu.org; Fri, 30 Jan 2015 11:23:28 -0500 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:54423) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHELt-0002jW-Ba for emacs-devel@gnu.org; Fri, 30 Jan 2015 11:23:25 -0500 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 16BD620A34 for ; Fri, 30 Jan 2015 11:23:25 -0500 (EST) Original-Received: from frontend2 ([10.202.2.161]) by compute3.internal (MEProxy); Fri, 30 Jan 2015 11:23:25 -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=4wpbkaxVb+Mnjh70Hh27H08UtoA=; b=WoJAi1rv7lYwcL6dZ7Lc KMzVhGn92+eBj+IKDnoEpkfZqkriRqq+QAypFd9erYfri8k5dIvT9SB1ra9oV5Hf 9525IIQxLsjlXHjurx6OGL3MYTRmUuUdV9ao5ltOoTJ4uXnw2sghroOIHY61tju4 UKtyDF73JNKka4LgbTU37Vk= X-Sasl-enc: I/DlZcia+0WClouU9F4xL5IEZYpd/AoqyTR9nJG6CKf8 1422635004 Original-Received: from blueberry (unknown [31.211.216.84]) by mail.messagingengine.com (Postfix) with ESMTPA id 38AA468017A; Fri, 30 Jan 2015 11:23:24 -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:182073 Archived-At: seq-group-by seems like a good idea, thanks! Nico Oleh Krehel writes: > On Fri, Jan 30, 2015 at 11:21 AM, Nicolas Petton wrote: >> >> Oleh Krehel writes: >> >>> Hi Nicolas, >>> >>> On Thu, Jan 29, 2015 at 11:06 PM, Nicolas Petton wrote: >>> >>>> Sure, `seq-range' would be a convenient way to create a sequence of >>>> numbers. A simple implementation could be: >>>> >>>> (defun seq-range (start end) >>>> (let ((lst nil)) >>>> (while (< start end) >>>> (push end lst) >>>> (setq end (1- end))) >>>> lst)) >>> >>> This is just `number-sequence' from subr.el. >> >> Indeed :) >> >> Nico >> -- >> Nicolas Petton >> http://nicolas-petton.fr >> > > 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? > > Oleh -- Nicolas Petton http://nicolas-petton.fr