[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash ff5ed7a 261/316: Extend -keep docs and tests
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash ff5ed7a 261/316: Extend -keep docs and tests |
Date: |
Mon, 15 Feb 2021 15:58:13 -0500 (EST) |
branch: externals/dash
commit ff5ed7a1ce632d563d669ffc7d71116e46a2cee1
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>
Extend -keep docs and tests
* dash.el (--keep): Extend docstring. Prefer push over !cons.
(-keep): Extend docstring.
* dev/examples.el (-keep): Extend tests.
* README.md:
* dash.texi: Regenerate docs.
---
README.md | 13 +++++++------
dash.el | 16 +++++++++++-----
dash.texi | 13 +++++++------
dev/examples.el | 11 ++++++++---
4 files changed, 33 insertions(+), 20 deletions(-)
diff --git a/README.md b/README.md
index 036cbcd..e87788b 100644
--- a/README.md
+++ b/README.md
@@ -749,14 +749,15 @@ Functions returning a modified copy of the input list.
#### -keep `(fn list)`
-Return a new list of the non-nil results of applying `fn` to the items in
`list`.
-
-If you want to select the original items satisfying a predicate use
[`-filter`](#-filter-pred-list).
+Return a new list of the non-nil results of applying `fn` to each item in
`list`.
+Like [`-filter`](#-filter-pred-list), but returns the non-nil results of `fn`
instead of
+the corresponding elements of `list`.
+Its anaphoric counterpart is `--keep`.
```el
-(-keep 'cdr '((1 2 3) (4 5) (6))) ;; => '((2 3) (5))
-(-keep (lambda (num) (when (> num 3) (* 10 num))) '(1 2 3 4 5 6)) ;; => '(40
50 60)
-(--keep (when (> it 3) (* 10 it)) '(1 2 3 4 5 6)) ;; => '(40 50 60)
+(-keep #'cdr '((1 2 3) (4 5) (6))) ;; => '((2 3) (5))
+(-keep (lambda (n) (and (> n 3) (* 10 n))) '(1 2 3 4 5 6)) ;; => '(40 50 60)
+(--keep (and (> it 3) (* 10 it)) '(1 2 3 4 5 6)) ;; => '(40 50 60)
```
#### -concat `(&rest lists)`
diff --git a/dash.el b/dash.el
index a800a1d..84cfbe8 100644
--- a/dash.el
+++ b/dash.el
@@ -515,18 +515,24 @@ The comparison is done with `equal'.
\n(fn ITEM LIST)")
(defmacro --keep (form list)
- "Anaphoric form of `-keep'."
+ "Eval FORM for each item in LIST and return the non-nil results.
+Like `--filter', but returns the non-nil results of FORM instead
+of the corresponding elements of LIST. Each element of LIST in
+turn is bound to `it' and its index within LIST to `it-index'
+before evaluating FORM.
+This is the anaphoric counterpart to `-keep'."
(declare (debug (form form)))
(let ((r (make-symbol "result"))
(m (make-symbol "mapped")))
`(let (,r)
- (--each ,list (let ((,m ,form)) (when ,m (!cons ,m ,r))))
+ (--each ,list (let ((,m ,form)) (when ,m (push ,m ,r))))
(nreverse ,r))))
(defun -keep (fn list)
- "Return a new list of the non-nil results of applying FN to the items in
LIST.
-
-If you want to select the original items satisfying a predicate use `-filter'."
+ "Return a new list of the non-nil results of applying FN to each item in
LIST.
+Like `-filter', but returns the non-nil results of FN instead of
+the corresponding elements of LIST.
+Its anaphoric counterpart is `--keep'."
(--keep (funcall fn it) list))
(defun -non-nil (list)
diff --git a/dash.texi b/dash.texi
index 1d2ac44..4f0f487 100644
--- a/dash.texi
+++ b/dash.texi
@@ -872,21 +872,22 @@ Functions returning a modified copy of the input list.
@anchor{-keep}
@defun -keep (fn list)
-Return a new list of the non-nil results of applying @var{fn} to the items in
@var{list}.
-
-If you want to select the original items satisfying a predicate use
@code{-filter} (@pxref{-filter}).
+Return a new list of the non-nil results of applying @var{fn} to each item in
@var{list}.
+Like @code{-filter} (@pxref{-filter}), but returns the non-nil results of
@var{fn} instead of
+the corresponding elements of @var{list}.
+Its anaphoric counterpart is @code{--keep}.
@example
@group
-(-keep 'cdr '((1 2 3) (4 5) (6)))
+(-keep #'cdr '((1 2 3) (4 5) (6)))
@result{} '((2 3) (5))
@end group
@group
-(-keep (lambda (num) (when (> num 3) (* 10 num))) '(1 2 3 4 5 6))
+(-keep (lambda (n) (and (> n 3) (* 10 n))) '(1 2 3 4 5 6))
@result{} '(40 50 60)
@end group
@group
-(--keep (when (> it 3) (* 10 it)) '(1 2 3 4 5 6))
+(--keep (and (> it 3) (* 10 it)) '(1 2 3 4 5 6))
@result{} '(40 50 60)
@end group
@end example
diff --git a/dev/examples.el b/dev/examples.el
index eb813f3..f376091 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -320,9 +320,14 @@ new list."
"Functions returning a modified copy of the input list."
(defexamples -keep
- (-keep 'cdr '((1 2 3) (4 5) (6))) => '((2 3) (5))
- (-keep (lambda (num) (when (> num 3) (* 10 num))) '(1 2 3 4 5 6)) => '(40
50 60)
- (--keep (when (> it 3) (* 10 it)) '(1 2 3 4 5 6)) => '(40 50 60))
+ (-keep #'cdr '((1 2 3) (4 5) (6))) => '((2 3) (5))
+ (-keep (lambda (n) (and (> n 3) (* 10 n))) '(1 2 3 4 5 6)) => '(40 50 60)
+ (--keep (and (> it 3) (* 10 it)) '(1 2 3 4 5 6)) => '(40 50 60)
+ (-keep #'null '(nil)) => '(t)
+ (--keep it '(nil)) => '()
+ (--keep t '(nil)) => '(t)
+ (--keep t '()) => '()
+ (-keep #'identity '()) => '())
(defexamples -concat
(-concat '(1)) => '(1)
- [elpa] externals/dash 51d81a5 308/316: Avoid using dash.el functions in macro bodies, (continued)
- [elpa] externals/dash 51d81a5 308/316: Avoid using dash.el functions in macro bodies, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 41b5681 310/316: Merge pull request #369 from blc/gut, ELPA Syncer, 2021/02/15
- [elpa] externals/dash cec8c0d 311/316: Rename approx-equal to more accurate approx=, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 4d40317 313/316: Update list of contributors, ELPA Syncer, 2021/02/15
- [elpa] externals/dash be4e939 314/316: ; Fix recent whitespace change in dev/examples.el., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0e97578 316/316: Release dash 2.18.0 and dash-functional 1.3.0, ELPA Syncer, 2021/02/15
- [elpa] externals/dash d98f5a0 235/316: Update for -iota, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0f13e5e 246/316: Prefer push over add-to-list, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 9703eac 249/316: ; Fix Edebug spec in last change, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 4fb9613 255/316: Avoid evaluating file-local variables, ELPA Syncer, 2021/02/15
- [elpa] externals/dash ff5ed7a 261/316: Extend -keep docs and tests,
ELPA Syncer <=
- [elpa] externals/dash 5d8de45 262/316: ; Fix recent typo in -filter & -remove docstrings, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 7fc72d9 263/316: Fix Markdown quoting, ELPA Syncer, 2021/02/15
- [elpa] externals/dash e5e5363 272/316: Merge pull request #367 from HKey/fix-handling-nil, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 8bd2887 269/316: Move pre-commit.sh under dev/, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 8599380 270/316: Optimize -is-prefix? and -is-suffix?, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 5362be7 275/316: Use actual advertised function signature in manual, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 926eb0b 280/316: Add forceful Makefile targets, ELPA Syncer, 2021/02/15
- [elpa] externals/dash eedc2af 279/316: Fix docstring Texinfo generation, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 7ee12ee 283/316: Use buffers for Texinfo generation, ELPA Syncer, 2021/02/15
- [elpa] externals/dash baf9147 285/316: Simplify Texinfo generation, ELPA Syncer, 2021/02/15