Subject: [PATCH] Use `seq-do' instead of `seq-map' for side-effects

From: Zach Shaftel <[email-masked]>
Date: Thu, 05 Jun 2025 23:18:26 -0400

Tags: patch

self explanatory i think.

In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.49, cairo version 1.18.4) of 2025-06-04 built on bigbox
Repository revision: 680fa61b5989b84c0e19ac568be012afd8345f0c
Repository branch: master
System Description: Arch Linux

Configured using:
 'configure --with-modules --without-xwidgets --with-native-compilation
 --with-tree-sitter --without-gsettings --without-gconf --without-gpm
 --with-pgtk --without-compress-install 'CFLAGS=-mtune=native
 -march=native -O2 -g -fuse-ld=mold''

>From ba328dd06ebc503d6bc7c1ab1f6c2c45bdf6f375 Mon Sep 17 00:00:00 2001
From: Zach Shaftel <[email-masked]>
Date: Thu, 5 Jun 2025 00:05:20 -0400
Subject: [PATCH] Use `seq-do' instead of `seq-map' for side-effects

* lisp/emacs-lisp/seq.el (seq-reverse): Use `seq-do' instead of
`seq-map' since it's being used for effect.
* lisp/emacs-lisp/seq.el (seq-map): Declare `important-return-value' so
the compiler will complain about it next time.
---
 lisp/emacs-lisp/seq.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index a7954e7614c..af425456fe1 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -195,6 +195,7 @@ seq-subseq
 
 (cl-defgeneric seq-map (function sequence)
   "Return the result of applying FUNCTION to each element of SEQUENCE."
+  (declare (important-return-value t))
   (let (result)
     (seq-do (lambda (elt)
               (push (funcall function elt) result))
@@ -295,9 +296,9 @@ seq-sort-by
 (cl-defgeneric seq-reverse (sequence)
   "Return a sequence with elements of SEQUENCE in reverse order."
   (let ((result '()))
-    (seq-map (lambda (elt)
-               (push elt result))
-             sequence)
+    (seq-do (lambda (elt)
+              (push elt result))
+            sequence)
     (seq-into result (type-of sequence))))
 
 ;; faster implementation for sequences (sequencep)
-- 
2.49.0