* doc/lispref/sequences.texi (Sequence Functions): Document it.
* lisp/emacs-lisp/seq.el (seq-keep): New function (bug#58278).
@end example
@end defun
+@defun seq-keep function sequence
+ This function returns a list of all non-@code{nil} results from
+calling @var{function} on the elements in @var{sequence}.
+
+@example
+@group
+(seq-keep #'cl-digit-char-p '(?6 ?a ?7))
+@result{} (6 7)
+@end group
+@end example
+
+@end defun
+
@defun seq-reduce function sequence initial-value
@cindex reducing sequences
This function returns the result of calling @var{function} with
This returns a list of the (zero-based) indices of elements matching a
given predicate in the specified sequence.
++++
+** New function 'seq-keep'.
+This is like 'seq-map', but removes all non-nil results from the
+returned list.
+
+++
** New arguments MESSAGE and TIMEOUT of 'set-transient-map'.
MESSAGE specifies a message to display after activating the transient
result))
(nreverse result)))
+(defun seq-keep (function sequence)
+ "Apply FUNCTION to SEQUENCE and return all non-nil results."
+ (delq nil (seq-map function sequence)))
+
(provide 'seq)
;;; seq.el ends here
(should (= (length list) 10000))
(should (= (length (seq-uniq (append list list))) 10000))))
+(ert-deftest test-seq-keep ()
+ (should (equal (seq-keep #'cl-digit-char-p '(?6 ?a ?7))
+ '(6 7)))
+ (should (equal (seq-keep #'cl-digit-char-p [?6 ?a ?7])
+ '(6 7))))
+
(provide 'seq-tests)
;;; seq-tests.el ends here