[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
- Re: Would seq-range and seq-mapcat be useful?, (continued)
- Re: Would seq-range and seq-mapcat be useful?, Stefan Monnier, 2015/01/29
- 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 Petton, 2015/01/30
What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?),
Mark Oteiza <=
- 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
- Re: seq-thread-first/last, Artur Malabarba, 2015/01/30