emacs-devel
[Top][All Lists]
Advanced

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

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


From: Mark Oteiza
Subject: What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?)
Date: Fri, 30 Jan 2015 03:20:04 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

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



reply via email to

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