emacs-elpa-diffs
[Top][All Lists]
Advanced

[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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]