mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
Add 'seq-keep'
* doc/lispref/sequences.texi (Sequence Functions): Document it. * lisp/emacs-lisp/seq.el (seq-keep): New function (bug#58278).
This commit is contained in:
parent
1d3d87cd67
commit
92df7cd923
4 changed files with 28 additions and 0 deletions
|
|
@ -698,6 +698,19 @@ the same type as @var{sequence}.
|
||||||
@end example
|
@end example
|
||||||
@end defun
|
@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
|
@defun seq-reduce function sequence initial-value
|
||||||
@cindex reducing sequences
|
@cindex reducing sequences
|
||||||
This function returns the result of calling @var{function} with
|
This function returns the result of calling @var{function} with
|
||||||
|
|
|
||||||
5
etc/NEWS
5
etc/NEWS
|
|
@ -3150,6 +3150,11 @@ These can be used for buttons in buffers and the like. See the
|
||||||
This returns a list of the (zero-based) indices of elements matching a
|
This returns a list of the (zero-based) indices of elements matching a
|
||||||
given predicate in the specified sequence.
|
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'.
|
** New arguments MESSAGE and TIMEOUT of 'set-transient-map'.
|
||||||
MESSAGE specifies a message to display after activating the transient
|
MESSAGE specifies a message to display after activating the transient
|
||||||
|
|
|
||||||
|
|
@ -695,5 +695,9 @@ which may be shorter."
|
||||||
result))
|
result))
|
||||||
(nreverse 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)
|
(provide 'seq)
|
||||||
;;; seq.el ends here
|
;;; seq.el ends here
|
||||||
|
|
|
||||||
|
|
@ -592,5 +592,11 @@ Evaluate BODY for each created sequence.
|
||||||
(should (= (length list) 10000))
|
(should (= (length list) 10000))
|
||||||
(should (= (length (seq-uniq (append list 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)
|
(provide 'seq-tests)
|
||||||
;;; seq-tests.el ends here
|
;;; seq-tests.el ends here
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue