[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#58278: Add new function seq-keep
From: |
Lars Ingebrigtsen |
Subject: |
bug#58278: Add new function seq-keep |
Date: |
Tue, 04 Oct 2022 15:47:16 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Jonas Bernoulli <jonas@bernoul.li> 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).
- bug#58278: Add new function seq-keep, (continued)
- bug#58278: Add new function seq-keep, Robert Pluim, 2022/10/04
- bug#58278: Add new function seq-keep, Lars Ingebrigtsen, 2022/10/04
- bug#58278: Add new function seq-keep, Robert Pluim, 2022/10/04
- bug#58278: Add new function seq-keep, Lars Ingebrigtsen, 2022/10/04
- bug#58278: Add new function seq-keep, Robert Pluim, 2022/10/04
- bug#58278: Add new function seq-keep, Lars Ingebrigtsen, 2022/10/04
- bug#58278: Add new function seq-keep, Robert Pluim, 2022/10/04
- bug#58278: Add new function seq-keep, Lars Ingebrigtsen, 2022/10/04
- bug#58278: Add new function seq-keep, Robert Pluim, 2022/10/04
bug#58278: Add new function seq-keep, Jonas Bernoulli, 2022/10/04