From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicolas Petton Newsgroups: gmane.emacs.devel Subject: Re: What about seq-slice? (Was: Would seq-range and seq-mapcat be useful?) Date: Fri, 30 Jan 2015 11:25:59 +0100 Message-ID: <87k304ef9k.fsf@petton.fr> References: <878uglwmra.fsf@petton.fr> <87iofoof2j.fsf@udel.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1422613615 16461 80.91.229.3 (30 Jan 2015 10:26:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 30 Jan 2015 10:26:55 +0000 (UTC) Cc: emacs-devel@gnu.org To: Mark Oteiza Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 30 11:26:52 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YH8mp-00070z-Sb for ged-emacs-devel@m.gmane.org; Fri, 30 Jan 2015 11:26:52 +0100 Original-Received: from localhost ([::1]:35897 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YH8mp-0001zD-4s for ged-emacs-devel@m.gmane.org; Fri, 30 Jan 2015 05:26:51 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YH8m4-0001EC-Um for emacs-devel@gnu.org; Fri, 30 Jan 2015 05:26:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YH8m1-0002cb-EF for emacs-devel@gnu.org; Fri, 30 Jan 2015 05:26:04 -0500 Original-Received: from out3-smtp.messagingengine.com ([66.111.4.27]:40902) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YH8m1-0002cX-AY for emacs-devel@gnu.org; Fri, 30 Jan 2015 05:26:01 -0500 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 36EFA20772 for ; Fri, 30 Jan 2015 05:26:01 -0500 (EST) Original-Received: from frontend1 ([10.202.2.160]) by compute2.internal (MEProxy); Fri, 30 Jan 2015 05:26:01 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:references:from:to:cc:subject :in-reply-to:date:message-id:mime-version:content-type; s= smtpout; bh=HTZTpbBS3jhJTwNK5h8aUjKhS0A=; b=FlDDHNQ8dGyLH2ycn3us avoECRR1sVmPggiOwUhLBaiCbRofV7MOADN4XGd/q26dkNcIT+s6URVXfSaKx50n N9fLtvCFmCC6msi4A5pwvvqLCjXkoYCifE4ojKMUB6cH6BD7aOk+kejrNzsonaWd jC3kEXv8bNxRjFEpHYKQWNc= X-Sasl-enc: n4rTK1QSrZ50K5bXLw4qHX/dWWf/jvEe6PEo/lVbfZPt 1422613560 Original-Received: from blueberry (unknown [31.211.216.84]) by mail.messagingengine.com (Postfix) with ESMTPA id 90387C0028C; Fri, 30 Jan 2015 05:26:00 -0500 (EST) User-agent: mu4e 0.9.9.6pre3; emacs 24.4.1 In-reply-to: <87iofoof2j.fsf@udel.edu> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.111.4.27 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:182040 Archived-At: Hi Mark, I'm not sure I understand how to use it. In which scenario would you find `seq-slice' useful? Nico Mark Oteiza writes: > Nicolas Petton 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