From: Michael Heerdegen <michael_heerdegen@web.de>
To: Emacs Development <emacs-devel@gnu.org>
Cc: Nicolas Petton <nicolas@petton.fr>,
Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Stream implementation of seq-mapn
Date: Mon, 18 Dec 2017 12:58:16 +0100 [thread overview]
Message-ID: <87lgi0fdt3.fsf@web.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 73 bytes --]
Hello,
I want to define `seq-mapn' for streams. This is what I have:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Implement-seq-mapn-for-streams.patch --]
[-- Type: text/x-diff, Size: 1520 bytes --]
From 46caedf7b85f4285e83f72646fa1d6940bd7ea00 Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@web.de>
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
[-- Attachment #3: Type: text/plain, Size: 229 bytes --]
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.
next reply other threads:[~2017-12-18 11:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-18 11:58 Michael Heerdegen [this message]
2017-12-18 12:32 ` Stream implementation of seq-mapn Nicolas Petton
2017-12-18 12:51 ` Michael Heerdegen
2017-12-18 13:50 ` Nicolas Petton
2017-12-19 13:05 ` Michael Heerdegen
2017-12-19 14:08 ` Nicolas Petton
2017-12-26 22:09 ` Michael Heerdegen
2017-12-29 9:04 ` Nicolas Petton
2017-12-30 14:28 ` Michael Heerdegen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lgi0fdt3.fsf@web.de \
--to=michael_heerdegen@web.de \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=nicolas@petton.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.