bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#67456: [PATCH] seq.el: Add functions for mapping over subsequences


From: Philip Kaludercic
Subject: bug#67456: [PATCH] seq.el: Add functions for mapping over subsequences
Date: Mon, 25 Dec 2023 20:26:18 +0000

Okamsn <okamsn@protonmail.com> writes:

> Hello,
>
> The attached features work like `cl-maplist` and `cl-mapl`, applying 
> functions to a sequence and to the remaining parts of a sequence.  For 
> example, `(seq-mapsub #'identity [1 2 3])` returns `([1 2 3] [2 3] [3])`.
>
> The patch adds a `seq-mapsub`, `seq-dosub`, and a `seq-doseqsub`, 
> similar to `seq-map`, `seq-do`, and `seq-doseq`, respectively.

How about adding a custom sequence type, that operates on sub-sequences
as elements?

--8<---------------cut here---------------start------------->8---
(cl-defstruct (subseq (:constructor seq-make-subseq (seq))) seq)

(cl-defmethod seq-elt ((seq subseq) n)
  (seq-subseq (subseq-seq seq) n (seq-length seq)))

(cl-defmethod seq-length ((seq subseq))
  (seq-length (subseq-seq seq)))

(cl-defmethod seq-do (fn (seq subseq))
  (seq-do fn (subseq-seq seq)))

;; etc.
--8<---------------cut here---------------end--------------->8---

It might not be that efficient either, but at least it doesn't require
more functions.





reply via email to

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