emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What about seq-slice? (Was: Would seq-range and seq-mapcat be useful


From: Nicolas Petton
Subject: Re: What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?)
Date: Fri, 30 Jan 2015 11:25:59 +0100
User-agent: mu4e 0.9.9.6pre3; emacs 24.4.1

Hi Mark,

I'm not sure I understand how to use it. In which scenario would you
find `seq-slice' useful?

Nico


Mark Oteiza <address@hidden> writes:

> Nicolas Petton <address@hidden> writes:
>
>> While using seq.el, I often miss functions like seq-mapcat and
>> seq-range. Do you think adding such functions would be a good addition
>> to seq.el?
>
> Coincidentally, I had been thinking about additions to seq.el.  I'm
> interested in having a function like Ruby's each_slice[0] method.  For
> example,
>
>     (defun seq-slice (seq n)
>       "Return a list of subsequences of SEQ, each a sequence of
>     length N.  The last subsequence may have less than N elements.
>     
>     If N is a negative integer or zero, a list containing SEQ is
>     returned."
>       (if (or (<= n 0)
>               (>= n (seq-length seq)))
>           (list seq)
>         (let ((copy (seq-copy seq))
>               (result '()))
>           (while (not (seq-empty-p copy))
>             (push (seq-take copy n) result)
>             (setq copy (seq-drop copy n)))
>           (nreverse result))))
>
> I didn't think dash.el had it until I realized it is named something
> else: -partition-all[1].
>
> [0]: http://ruby-doc.org/core-2.2.0/Enumerable.html#method-i-each_slice
> [1]: https://github.com/magnars/dash.el/blob/master/dash.el#L730

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




reply via email to

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