[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 9ad0d2b 266/316: Extend -map-indexed docs and test
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash 9ad0d2b 266/316: Extend -map-indexed docs and tests |
Date: |
Mon, 15 Feb 2021 15:58:14 -0500 (EST) |
branch: externals/dash
commit 9ad0d2b972582d43ae19de4111d1f182cbbd2256
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>
Extend -map-indexed docs and tests
* dash.el (--map): Fix recent typo in docstring.
(--map-indexed): Extend docstring. Prefer push over !cons.
(-map-indexed): Extend docstring.
* dev/examples.el (-map-indexed): Extend tests.
* README.md:
* dash.texi: Regenerate.
---
README.md | 10 ++++++----
dash.el | 21 ++++++++++++++-------
dash.texi | 13 +++++++++----
dev/examples.el | 7 ++++++-
4 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/README.md b/README.md
index 4cb05dc..338fa19 100644
--- a/README.md
+++ b/README.md
@@ -433,15 +433,17 @@ See also: [`-map-when`](#-map-when-pred-rep-list),
[`-replace-last`](#-replace-l
#### -map-indexed `(fn list)`
-Return a new list consisting of the result of (`fn` index item) for each item
in `list`.
+Apply `fn` to each index and item in `list` and return the list of results.
+This is like [`-map`](#-map-fn-list), but `fn` takes two arguments: the index
of the
+current element within `list`, and the element itself.
-In the anaphoric form `--map-indexed`, the index is exposed as symbol
`it-index`.
-
-See also: [`-each-indexed`](#-each-indexed-list-fn).
+This function's anaphoric counterpart is `--map-indexed`.
+For a side-effecting variant, see also
[`-each-indexed`](#-each-indexed-list-fn).
```el
(-map-indexed (lambda (index item) (- item index)) '(1 2 3 4)) ;; => '(1 1 1 1)
(--map-indexed (- it it-index) '(1 2 3 4)) ;; => '(1 1 1 1)
+(-map-indexed #'* '(1 2 3 4)) ;; => '(0 2 6 12)
```
#### -annotate `(fn list)`
diff --git a/dash.el b/dash.el
index 3092da5..74a20d7 100644
--- a/dash.el
+++ b/dash.el
@@ -204,7 +204,8 @@ This function's anaphoric counterpart is `--map'."
(defmacro --map (form list)
"Eval FORM for each item in LIST and return the list of results.
Each element of LIST in turn is bound to `it' before evaluating
-BODY.
+FORM.
+
This is the anaphoric counterpart to `-map'."
(declare (debug (def-form form)))
`(mapcar (lambda (it) (ignore it) ,form) ,list))
@@ -541,20 +542,26 @@ Its anaphoric counterpart is `--keep'."
(--filter it list))
(defmacro --map-indexed (form list)
- "Anaphoric form of `-map-indexed'."
+ "Eval FORM for each item in LIST and return the list of results.
+Each element of LIST in turn is bound to `it' and its index
+within LIST to `it-index' before evaluating FORM. This is like
+`--map', but additionally makes `it-index' available to FORM.
+
+This is the anaphoric counterpart to `-map-indexed'."
(declare (debug (form form)))
(let ((r (make-symbol "result")))
`(let (,r)
(--each ,list
- (!cons ,form ,r))
+ (push ,form ,r))
(nreverse ,r))))
(defun -map-indexed (fn list)
- "Return a new list consisting of the result of (FN index item) for each item
in LIST.
-
-In the anaphoric form `--map-indexed', the index is exposed as symbol
`it-index'.
+ "Apply FN to each index and item in LIST and return the list of results.
+This is like `-map', but FN takes two arguments: the index of the
+current element within LIST, and the element itself.
-See also: `-each-indexed'."
+This function's anaphoric counterpart is `--map-indexed'.
+For a side-effecting variant, see also `-each-indexed'."
(--map-indexed (funcall fn it-index it) list))
(defmacro --map-when (pred rep list)
diff --git a/dash.texi b/dash.texi
index 553809d..6a4f087 100644
--- a/dash.texi
+++ b/dash.texi
@@ -344,11 +344,12 @@ See also: @code{-map-when} (@pxref{-map-when}),
@code{-replace-last} (@pxref{-re
@anchor{-map-indexed}
@defun -map-indexed (fn list)
-Return a new list consisting of the result of (@var{fn} index item) for each
item in @var{list}.
+Apply @var{fn} to each index and item in @var{list} and return the list of
results.
+This is like @code{-map} (@pxref{-map}), but @var{fn} takes two arguments: the
index of the
+current element within @var{list}, and the element itself.
-In the anaphoric form @code{--map-indexed}, the index is exposed as symbol
@code{it-index}.
-
-See also: @code{-each-indexed} (@pxref{-each-indexed}).
+This function's anaphoric counterpart is @code{--map-indexed}.
+For a side-effecting variant, see also @code{-each-indexed}
(@pxref{-each-indexed}).
@example
@group
@@ -359,6 +360,10 @@ See also: @code{-each-indexed} (@pxref{-each-indexed}).
(--map-indexed (- it it-index) '(1 2 3 4))
@result{} '(1 1 1 1)
@end group
+@group
+(-map-indexed #'* '(1 2 3 4))
+ @result{} '(0 2 6 12)
+@end group
@end example
@end defun
diff --git a/dev/examples.el b/dev/examples.el
index f376091..a11f3fb 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -95,7 +95,12 @@ new list."
(defexamples -map-indexed
(-map-indexed (lambda (index item) (- item index)) '(1 2 3 4)) => '(1 1 1
1)
- (--map-indexed (- it it-index) '(1 2 3 4)) => '(1 1 1 1))
+ (--map-indexed (- it it-index) '(1 2 3 4)) => '(1 1 1 1)
+ (-map-indexed #'* '(1 2 3 4)) => '(0 2 6 12)
+ (-map-indexed #'ignore '(1 2 3 4)) => '(nil nil nil nil)
+ (-map-indexed #'ignore '()) => '()
+ (--map-indexed t '(1 2 3 4)) => '(t t t t)
+ (--map-indexed t '()) => '())
(defexamples -annotate
(-annotate '1+ '(1 2 3)) => '((2 . 1) (3 . 2) (4 . 3))
- [elpa] externals/dash bf8a462 243/316: Partially revert last change, (continued)
- [elpa] externals/dash bf8a462 243/316: Partially revert last change, ELPA Syncer, 2021/02/15
- [elpa] externals/dash d7d0acb 242/316: Don't call eval, ELPA Syncer, 2021/02/15
- [elpa] externals/dash bf8d876 238/316: Merge pull request #363 from blc/list, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 76ace7f 240/316: Fix error signaling, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 1ccf08d 244/316: ; Fix last change, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 2625bc5 247/316: Don't use insert-file-contents-literally, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 7583e65 248/316: Revert --map to using mapcar, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 6f5888c 251/316: Extend --filter and --remove docs and tests, ELPA Syncer, 2021/02/15
- [elpa] externals/dash db45ee7 252/316: Optimize -remove-first a bit, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0e5acda 260/316: Simplify -non-nil, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 9ad0d2b 266/316: Extend -map-indexed docs and tests,
ELPA Syncer <=
- [elpa] externals/dash f61769d 256/316: * dash.el (dash--keywords): Prefer rx., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 2aeb4e4 264/316: Use actual advertised function signature in README, ELPA Syncer, 2021/02/15
- [elpa] externals/dash a536770 267/316: Prefer relative image links in README, ELPA Syncer, 2021/02/15
- [elpa] externals/dash ce4a344 258/316: Eliminate odd? from examples, ELPA Syncer, 2021/02/15
- [elpa] externals/dash f3ae7bb 259/316: Alias -remove-item to remove, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 525ede2 265/316: Improve docstring Markdown formatting, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 4a32a5d 257/316: Write -remove-last in terms of --remove-last, ELPA Syncer, 2021/02/15
- [elpa] externals/dash cbd3b29 268/316: * .elpaignore: Exclude dev/ from GNU ELPA tarball., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 2a10547 271/316: Fix handling nils of -some-->, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0789fd0 273/316: Fix -some--> docstring and Edebug spec, ELPA Syncer, 2021/02/15