Subject: Re: bug#58278: Add new function seq-keep

From: Lars Ingebrigtsen <[email-masked]>
Date: Tue, 04 Oct 2022 15:47:16 +0200

Jonas Bernoulli <[email-masked]> writes:

> Yes, that would be an improvement.  Some (but certainly not all)
> uses of dash's `-keep' look something like
>
>   (-keep (lambda (elt)
>            (and (symbolp elt)
>                 (symbol-name elt)))
>          sequence)
>
> and
>
>   (seq-keep #'symbol-name sequence #'symbolp)
>
> would be much nicer in those situations.

Hm...  That's not exactly what I was thinking here.  I was thinking

(cl-defgeneric seq-keep (func sequence &optional pred)
  (if pred
      (seq-filter pred (seq-mapcar func sequence))
    (delq nil (seq-mapcar func sequence))))

which is the traditional "keep" semantics, but allows extending the
concept of "keep" to more than "is non-nil".

But that may well be an overcomplication -- in the unusual cases where
it's not nil that people want to keep, they can just type

  (seq-filter pred (seq-mapcar func sequence))

themselves, which has very clear semantics.

So I think, on second consideration, I'd rather just go with

(cl-defgeneric seq-keep (func sequence)
  (delq nil (seq-mapcar func sequence)))

like you originally suggested (but with just an argument name change).