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

From: Robert Pluim <[email-masked]>
Date: Tue, 04 Oct 2022 12:05:51 +0200

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

    Lars> 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)))

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

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

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

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

How is this different from 'cl-mapcan'? (apart from the syntactic sugar)

Robert
--