bug#81581: [PATCH 1/1] Add a LESSP argument to 'seq-min' and 'seq-max'

Eli Zaretskii <[email protected]>
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
> From: Philip Kaludercic <[email protected]>
> Date: Sat, 08 Aug 2026 19:59:57 +0000
> 
> -(cl-defgeneric seq-min (sequence)
> +(cl-defgeneric seq-min (sequence &optional lessp)
>    "Return the smallest element of SEQUENCE.
> -SEQUENCE must be a sequence of numbers or markers."
> -  (apply #'min (seq-into sequence 'list)))
> +Values are compared according to the optional parameter LESSP, which
> +defaults to `value<'."
> +  (unless lessp (setq lessp #'value<))
> +  (let ((fresh (eval-when-compile (make-symbol "fresh"))))
> +    (seq-reduce
> +     (lambda (acc elt)
> +       (cond
> +        ((eq acc fresh) elt)
> +        ((funcall lessp acc elt) acc)
> +        (t elt)))
> +     sequence
> +     fresh)))

How about optimizing for the default nil value of LESSP?  The original
implementation should be faster than the modified one, so how about
keeping the original performance for those who don't need a fancy
comparison function?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.