emacs-devel
[Top][All Lists]
Advanced

[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 10:28:24 +0100
User-agent: mu4e 0.9.9.6pre3; emacs 24.4.1

Oleh Krehel <address@hidden> writes:

> Nicolas Petton <address@hidden> writes:
>
>> 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?
>>
>
> I like `seq-group-by`.
>
> I'm not sure about `seq-mapcat`, since there is `cl-mapcan` (although
> it's destructive), I guess `seq-mapcat` would be fine.
>
> And I would prefer the name `seq-partition` instead of `seq-slice`,
> since `partition' is a Clojure name with same effect, and slice means
> something different in Python.

Yes, I felt the same.

Nico
-- 
Nicolas Petton
http://nicolas-petton.fr




reply via email to

[Prev in Thread] Current Thread [Next in Thread]