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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dash 4a32a5d 257/316: Write -remove-last in terms of --


From: ELPA Syncer
Subject: [elpa] externals/dash 4a32a5d 257/316: Write -remove-last in terms of --remove-last
Date: Mon, 15 Feb 2021 15:58:12 -0500 (EST)

branch: externals/dash
commit 4a32a5dc088d96a271a993aaa06e377af7995ebc
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>

    Write -remove-last in terms of --remove-last
    
    * dash.el (-remove-last): Move logic from here...
    (--remove-last): ...to here.
    * dev/examples.el (-remove-last): Improve and extend tests.
    
    * README.md:
    * dash.texi: Regenerate docs.
---
 README.md       | 15 ++++++++-------
 dash.el         | 25 +++++++++++++++----------
 dash.texi       | 19 ++++++++++---------
 dev/examples.el | 30 +++++++++++++++++++++++++-----
 4 files changed, 58 insertions(+), 31 deletions(-)

diff --git a/README.md b/README.md
index 8979cb3..91e31bc 100644
--- a/README.md
+++ b/README.md
@@ -558,15 +558,16 @@ See also [`-map-first`](#-map-first-pred-rep-list), 
[`-remove-item`](#-remove-it
 
 #### -remove-last `(pred list)`
 
-Return a new list with the last item matching `pred` removed.
-
-Alias: `-reject-last`
-
-See also: [`-remove`](#-remove-pred-list), 
[`-map-last`](#-map-last-pred-rep-list)
+Remove the last item from `list` for which `pred` returns non-nil.
+The result is a copy of `list` regardless of whether an element is
+removed.
+Alias: `-reject-last`.
+This function's anaphoric counterpart is `--remove-last`.
+See also [`-map-last`](#-map-last-pred-rep-list), 
[`-remove-item`](#-remove-item-item-list), and 
[`-remove-first`](#-remove-first-pred-list).
 
 ```el
-(-remove-last 'even? '(1 3 5 4 7 8 10 11)) ;; => '(1 3 5 4 7 8 11)
-(-remove-last 'stringp '(1 2 "last" "second" "third")) ;; => '(1 2 "last" 
"second")
+(-remove-last #'natnump '(1 3 5 4 7 8 10 -11)) ;; => '(1 3 5 4 7 8 -11)
+(-remove-last #'stringp '(1 2 "last" "second")) ;; => '(1 2 "last")
 (--remove-last (> it 3) '(1 2 3 4 5 6 7 8 9 10)) ;; => '(1 2 3 4 5 6 7 8 9)
 ```
 
diff --git a/dash.el b/dash.el
index 66fa4a2..d499928 100644
--- a/dash.el
+++ b/dash.el
@@ -488,18 +488,23 @@ See also `-map-first', `-remove-item', and 
`-remove-last'."
 (defalias '-reject-first '-remove-first)
 (defalias '--reject-first '--remove-first)
 
-(defun -remove-last (pred list)
-  "Return a new list with the last item matching PRED removed.
-
-Alias: `-reject-last'
-
-See also: `-remove', `-map-last'"
-  (nreverse (-remove-first pred (reverse list))))
-
 (defmacro --remove-last (form list)
-  "Anaphoric form of `-remove-last'."
+  "Remove the last item from LIST for which FORM evals to non-nil.
+Each element of LIST in turn is bound to `it' before evaluating
+FORM.  The result is a copy of LIST regardless of whether an
+element is removed.
+This is the anaphoric counterpart to `-remove-last'."
   (declare (debug (form form)))
-  `(-remove-last (lambda (it) ,form) ,list))
+  `(nreverse (--remove-first ,form (reverse ,list))))
+
+(defun -remove-last (pred list)
+  "Remove the last item from LIST for which PRED returns non-nil.
+The result is a copy of LIST regardless of whether an element is
+removed.
+Alias: `-reject-last'.
+This function's anaphoric counterpart is `--remove-last'.
+See also `-map-last', `-remove-item', and `-remove-first'."
+  (--remove-last (funcall pred it) list))
 
 (defalias '-reject-last '-remove-last)
 (defalias '--reject-last '--remove-last)
diff --git a/dash.texi b/dash.texi
index f69b59f..ba418e1 100644
--- a/dash.texi
+++ b/dash.texi
@@ -555,20 +555,21 @@ See also @code{-map-first} (@pxref{-map-first}), 
@code{-remove-item} (@pxref{-re
 
 @anchor{-remove-last}
 @defun -remove-last (pred list)
-Return a new list with the last item matching @var{pred} removed.
-
-Alias: @code{-reject-last}
-
-See also: @code{-remove} (@pxref{-remove}), @code{-map-last} 
(@pxref{-map-last})
+Remove the last item from @var{list} for which @var{pred} returns non-nil.
+The result is a copy of @var{list} regardless of whether an element is
+removed.
+Alias: @code{-reject-last}.
+This function's anaphoric counterpart is @code{--remove-last}.
+See also @code{-map-last} (@pxref{-map-last}), @code{-remove-item} 
(@pxref{-remove-item}), and @code{-remove-first} (@pxref{-remove-first}).
 
 @example
 @group
-(-remove-last 'even? '(1 3 5 4 7 8 10 11))
-    @result{} '(1 3 5 4 7 8 11)
+(-remove-last #'natnump '(1 3 5 4 7 8 10 -11))
+    @result{} '(1 3 5 4 7 8 -11)
 @end group
 @group
-(-remove-last 'stringp '(1 2 "last" "second" "third"))
-    @result{} '(1 2 "last" "second")
+(-remove-last #'stringp '(1 2 "last" "second"))
+    @result{} '(1 2 "last")
 @end group
 @group
 (--remove-last (> it 3) '(1 2 3 4 5 6 7 8 9 10))
diff --git a/dev/examples.el b/dev/examples.el
index e42b34d..76f4b20 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -172,12 +172,32 @@ new list."
     (let ((l (list 1 2))) (setcar (-remove-first #'null l) 0) l) => '(1 2))
 
   (defexamples -remove-last
-    (-remove-last 'even? '(1 3 5 4 7 8 10 11)) => '(1 3 5 4 7 8 11)
-    (-remove-last 'stringp '(1 2 "last" "second" "third")) => '(1 2 "last" 
"second")
+    (-remove-last #'natnump '(1 3 5 4 7 8 10 -11)) => '(1 3 5 4 7 8 -11)
+    (-remove-last #'stringp '(1 2 "last" "second")) => '(1 2 "last")
     (--remove-last (> it 3) '(1 2 3 4 5 6 7 8 9 10)) => '(1 2 3 4 5 6 7 8 9)
-    ;; the next two tests assert that the input list is not modified #158
-    (let ((l '(1 2 3))) (list (--remove-last (< it 2) l) l)) => '((2 3) (1 2 
3))
-    (let ((l '(1 2 3))) (list (--remove-last (< it 4) l) l)) => '((1 2) (1 2 
3)))
+    ;; The next two tests assert that the input list is not modified (#158).
+    (let ((l (list 1 2))) (setcar (--remove-last (= it 2) l) 0) l) => '(1 2)
+    (let ((l (list 1 2))) (setcar (--remove-last (= it 0) l) 0) l) => '(1 2)
+    (-remove-last #'identity '()) => '()
+    (-remove-last #'identity '(1)) => '()
+    (-remove-last #'identity '(nil)) => '(nil)
+    (-remove-last #'identity '(1 2)) => '(1)
+    (-remove-last #'identity '(1 nil)) => '(nil)
+    (--remove-last t '()) => '()
+    (--remove-last t '(1)) => '()
+    (--remove-last t '(nil)) => '()
+    (--remove-last t '(1 2)) => '(1)
+    (--remove-last t '(1 2 nil)) => '(1 2)
+    (--remove-last it '(1 nil)) => '(nil)
+    (-remove-last #'null '()) => '()
+    (-remove-last #'null '(1)) => '(1)
+    (-remove-last #'null '(nil)) => '()
+    (-remove-last #'null '(1 2)) => '(1 2)
+    (-remove-last #'null '(nil 1)) => '(1)
+    (--remove-last nil '()) => '()
+    (--remove-last nil '(1)) => '(1)
+    (--remove-last nil '(nil)) => '(nil)
+    (--remove-last nil '(1 2)) => '(1 2))
 
   (defexamples -remove-item
     (-remove-item 3 '(1 2 3 2 3 4 5 3)) => '(1 2 2 4 5)



reply via email to

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