[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)
- [elpa] externals/dash 6f5888c 251/316: Extend --filter and --remove docs and tests, (continued)
- [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, 2021/02/15
- [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 <=
- [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
- [elpa] externals/dash e0254c5 274/316: * dash.el (-doto): Fix Edebug spec., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 46e43c0 277/316: Fix long-standing typo in Texinfo generation, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 65eeaf6 278/316: Fix long-standing typo in examples, ELPA Syncer, 2021/02/15
- [elpa] externals/dash dbbf617 281/316: Remove dead code from examples-to-info.el, ELPA Syncer, 2021/02/15
- [elpa] externals/dash ee9bceb 284/316: Leave Texinfo docstring indentation as is, ELPA Syncer, 2021/02/15
- [elpa] externals/dash a6b16ea 286/316: Localize 'nil -> '() replacement in Texinfo, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 56db327 287/316: Fix printing in Emacs < 27, ELPA Syncer, 2021/02/15