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

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

Jonas Bernoulli <[email-masked]> writes:

> Unfortunately I cannot find a replacement for `-keep', which I have been
> using a lot.  I propose that we add something like:
>
>   (cl-defgeneric seq-keep (pred sequence)
>     "Return a list of all non-nil results of (PRED element) for elements in SEQUENCE."
>     (delq nil (seq-map (lambda (elt) (funcall pred elt))
>                        sequence)))

Hm...  well, here PRED isn't a predicate, really, but a transforming
function?  But you wish to filter out the nil results of that
transforming function.

That sounds useful -- there's more than a 100 matches for "delq
nil.*map" in-tree only -- but it's slightly confusing that the function
isn't altogether a predicate, but only kinda.  Would a function
signature like

(cl-defgeneric seq-keep (function sequence &optional pred)
  ...)

make more sense for this combination of map/filter?  (The default
predicate would, of course, be "not null".)