[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Would seq-range and seq-mapcat be useful?
From: |
Nicolas Petton |
Subject: |
Re: Would seq-range and seq-mapcat be useful? |
Date: |
Mon, 02 Feb 2015 01:11:07 +0100 |
User-agent: |
mu4e 0.9.9.6pre3; emacs 24.4.1 |
Oleh Krehel <address@hidden> 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
- Re: Would seq-range and seq-mapcat be useful?,
Nicolas Petton <=