From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: Stream implementation of seq-mapn Date: Mon, 18 Dec 2017 12:58:16 +0100 Message-ID: <87lgi0fdt3.fsf@web.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1513598200 22165 195.159.176.226 (18 Dec 2017 11:56:40 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 18 Dec 2017 11:56:40 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Nicolas Petton , Stefan Monnier To: Emacs Development Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Dec 18 12:56:36 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eQu26-0005MC-NV for ged-emacs-devel@m.gmane.org; Mon, 18 Dec 2017 12:56:34 +0100 Original-Received: from localhost ([::1]:58140 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQu45-0001aY-21 for ged-emacs-devel@m.gmane.org; Mon, 18 Dec 2017 06:58:37 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46757) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQu3y-0001aI-Gd for emacs-devel@gnu.org; Mon, 18 Dec 2017 06:58:31 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eQu3t-0000Un-KZ for emacs-devel@gnu.org; Mon, 18 Dec 2017 06:58:30 -0500 Original-Received: from mout.web.de ([212.227.15.14]:51000) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eQu3t-0000Te-8h for emacs-devel@gnu.org; Mon, 18 Dec 2017 06:58:25 -0500 Original-Received: from drachen.dragon ([88.74.120.211]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0M2dt7-1fGFd11ac9-00sNV0; Mon, 18 Dec 2017 12:58:18 +0100 X-Provags-ID: V03:K0:wgCZig9bs7XF4PbXv6CSP0UjA6GUs75VBlHLHMPGhMZ3L76uqub yMmyRizTWyYqMn/zUjVBB1g2YOmcSlf1mPLarQ2WRx9HE9fkYAnYVBBJymnU8mcoK19LuR9 TtBYay09AtSa2i7UV1qqLMk6edNnbLw8t4Wtf0iEAX9lpe0YYJUhWmbiOI+K9sSaTkyRpiD 3CECyBjY4WRd4TxqNeRsw== X-UI-Out-Filterresults: notjunk:1;V01:K0:CK79CFk/HPI=:R6TEoy7nuDOWcEJpVEzk44 UwI+B02jOoWnW/WA6Wtbfca1nWBFk8yUuv7ni4mCYRup6YBURqKAs5tc6YGgLOyYDmAPP2ppE rNeYzGU0UKkq5EuQSmA4VMK0eDpD19NFYQKad4CtGRYUmRJAaDmxZ7O0DwhyjTzrmUW29oE7X ykV1ZFx/GryOs9xKFG/mW8T1yj2FV90VSGTjBK5m87y0xMd216SQnG1ZxsSvrRBck1DTHIc3O 6aFM2Mbzz21wJ+IxilngAmxbEiZXFkZUDvfWdJIXtQy/PVbvWPjRuA43OZ0Q58KvAnuNb2NhK 5xmxCm0yOJtFeVuJszS4J7Io9uxEJCWPiC/mEkQziNEBZ976rYbwRqYSFfCMcxgHyGLjbOcax ZSiz3salejs4m7l/HEXDYM+32l810JD+zH9Q/2XB3ETZQaOFu7M39k/OjU9uU32BcjFaeMxaL 1R+w4L5trmywG78bTIM46HafqDqpDG6CYvJgdi5GEzWKyA1P2cQ2QS1o+WySTgk4XUF5+iMEx NXZLE8QXr+JQY+EUz6c8hRiZ12a0hiUd5js5bT94FibWQxypyC+F6prEffSHrtvfOfqeBbW7y 33SCiLskArKunK9svLyG3gyWyHESVWPXelpYELsQ5/xTrNN1QY2Wc4zcRAOWyAsnRHJgSHSMu hvhwWHMLdNaXAVYd655x1IpWP5Xvhmpd6x24WjXxraoRTCGg+2Vwjx/pDwK9cMdsbIMTzyj1f usdb8ew9fS3pFUVQFu+iBR144DRLS8kEKrMH4ZZJAUyqxUEOgf2NGns0QPgQt9ycEx753DHD X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.15.14 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:221210 Archived-At: --=-=-= Content-Type: text/plain Hello, I want to define `seq-mapn' for streams. This is what I have: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Implement-seq-mapn-for-streams.patch >From 46caedf7b85f4285e83f72646fa1d6940bd7ea00 Mon Sep 17 00:00:00 2001 From: Michael Heerdegen Date: Mon, 18 Dec 2017 12:49:38 +0100 Subject: [PATCH] Implement `seq-mapn' for streams --- packages/stream/stream.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/stream/stream.el b/packages/stream/stream.el index 810adf90d..a0e851015 100644 --- a/packages/stream/stream.el +++ b/packages/stream/stream.el @@ -318,6 +318,27 @@ applications of FUNCTION on each element of STREAM in succession." (cons (funcall function (stream-first stream)) (seq-map function (stream-rest stream)))))) +(cl-defmethod seq-mapn (function (stream stream) &rest streams) + "Map FUNCTION over the STREAMS. + +Example: this prints the first ten Fibonacci numbers: + + (letrec ((fibs (stream-cons + 1 + (stream-cons + 1 + (seq-mapn #'+ fibs (stream-rest fibs)))))) + (seq-do #'print (seq-take fibs 10))) + +\(fn FUNCTION STREAMS...)" + (if (not (cl-every #'streamp streams)) + (cl-call-next-method) + (cl-callf2 cons stream streams) + (stream-make + (unless (cl-some #'seq-empty-p streams) + (cons (apply function (mapcar #'stream-first streams)) + (apply #'seq-mapn function (mapcar #'stream-rest streams))))))) + (cl-defmethod seq-do (function (stream stream)) "Evaluate FUNCTION for each element of STREAM eagerly, and return nil. -- 2.15.1 --=-=-= Content-Type: text/plain Questions: (1) Is it ok to implement it with `cl-call-next-method' this way? (2) When I do C-h f seq-mapn, the signature of this new method is printed like | (arg2 (arg3 stream) &rest rest) Why is that? Thanks, Michael. --=-=-=--