[Top][All Lists]

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

Re: What about seq-slice?

From: Mark Oteiza
Subject: Re: What about seq-slice?
Date: Fri, 30 Jan 2015 12:17:28 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Nicolas Petton <address@hidden> writes:
> Mark Oteiza <address@hidden> writes:
>> 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
> Hi Mark,
> I'm not sure I understand how to use it. In which scenario would you
> find `seq-slice' useful?

When one has a large number of things but is only "allowed" to use N of
them at a time.  For instance, a large number of usernames and an API
that limits the number of users in a single query.

reply via email to

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