unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Nicolas Petton <nicolas@petton.fr>
To: Oleh Krehel <ohwoeowho@gmail.com>
Cc: Nicolas Petton <nicolas@petton.fr>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	emacs-devel <emacs-devel@gnu.org>
Subject: Re: Would seq-range and seq-mapcat be useful?
Date: Fri, 30 Jan 2015 17:23:23 +0100	[thread overview]
Message-ID: <87386sdypw.fsf@petton.fr> (raw)
In-Reply-To: <CAA01p3quKTexwMSBS-Umb10gVMF6LW7YuXR3erUjBCPC1pjeSA@mail.gmail.com>

seq-group-by seems like a good idea, thanks!

Nico


Oleh Krehel <ohwoeowho@gmail.com> writes:

> On Fri, Jan 30, 2015 at 11:21 AM, Nicolas Petton <nicolas@petton.fr> wrote:
>>
>> Oleh Krehel <ohwoeowho@gmail.com> writes:
>>
>>> Hi Nicolas,
>>>
>>> On Thu, Jan 29, 2015 at 11:06 PM, Nicolas Petton <nicolas@petton.fr> 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




  parent reply	other threads:[~2015-01-30 16:23 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-29 16:54 Would seq-range and seq-mapcat be useful? Nicolas Petton
2015-01-29 18:02 ` Artur Malabarba
2015-01-29 22:03   ` Nicolas Petton
2015-01-29 21:40 ` Stefan Monnier
2015-01-29 22:06   ` Nicolas Petton
2015-01-30  6:09     ` Stefan Monnier
2015-01-30  8:00     ` Oleh Krehel
2015-01-30 10:21       ` Nicolas Petton
2015-01-30 15:38         ` Oleh Krehel
2015-01-30 15:59           ` Nicolas Richard
2015-01-30 16:04             ` Oleh Krehel
2015-01-30 16:05               ` Oleh Krehel
2015-01-30 16:36               ` Nicolas Richard
2015-01-30 16:51                 ` Oleh Krehel
2015-01-30 16:23           ` Nicolas Petton [this message]
2015-02-02  0:11           ` Nicolas Petton
2015-02-02  7:49             ` Oleh Krehel
2015-02-02  9:28               ` Nicolas Petton
2015-02-02 18:34                 ` Mark Oteiza
2015-02-02 18:39                   ` Oleh Krehel
2015-02-04 12:02     ` Ted Zlatanov
2015-01-30  8:20 ` What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?) Mark Oteiza
2015-01-30 10:25   ` Nicolas Petton
2015-01-30 11:09     ` seq-thread-first/last (was: What about seq-slice?) Michael Heerdegen
2015-01-30 11:59       ` Nicolas Petton
2015-01-30 12:08         ` seq-thread-first/last Michael Heerdegen
2015-01-30 12:21           ` seq-thread-first/last Nicolas Petton
2015-01-30 12:17         ` seq-thread-first/last David Kastrup
2015-01-30 12:25           ` seq-thread-first/last Nicolas Petton
2015-01-30 12:33           ` seq-thread-first/last Michael Heerdegen
2015-01-30 12:58             ` seq-thread-first/last Bozhidar Batsov
2015-01-30 14:02               ` seq-thread-first/last Artur Malabarba
2015-01-30 14:15                 ` seq-thread-first/last Michael Heerdegen
2015-01-30 17:17     ` What about seq-slice? Mark Oteiza

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87386sdypw.fsf@petton.fr \
    --to=nicolas@petton.fr \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=ohwoeowho@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).