[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: |
Fri, 30 Jan 2015 17:23:23 +0100 |
User-agent: |
mu4e 0.9.9.6pre3; emacs 24.4.1 |
seq-group-by seems like a good idea, thanks!
Nico
Oleh Krehel <address@hidden> writes:
> On Fri, Jan 30, 2015 at 11:21 AM, Nicolas Petton <address@hidden> wrote:
>>
>> Oleh Krehel <address@hidden> writes:
>>
>>> Hi Nicolas,
>>>
>>> On Thu, Jan 29, 2015 at 11:06 PM, Nicolas Petton <address@hidden> 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
- Re: Would seq-range and seq-mapcat be useful?, (continued)
- Re: Would seq-range and seq-mapcat be useful?, Nicolas Petton, 2015/01/29
- Re: Would seq-range and seq-mapcat be useful?, Stefan Monnier, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Oleh Krehel, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Nicolas Petton, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Oleh Krehel, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Nicolas Richard, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Oleh Krehel, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Oleh Krehel, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Nicolas Richard, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?, Oleh Krehel, 2015/01/30
- Re: Would seq-range and seq-mapcat be useful?,
Nicolas Petton <=
What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?), Mark Oteiza, 2015/01/30
- Re: What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?), Nicolas Petton, 2015/01/30
- Re: seq-thread-first/last, David Kastrup, 2015/01/30
- Re: seq-thread-first/last, Nicolas Petton, 2015/01/30
- Re: seq-thread-first/last, Michael Heerdegen, 2015/01/30
- Re: seq-thread-first/last, Bozhidar Batsov, 2015/01/30