[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 7cc0149 021/316: [#99] Add -take-last and -drop-la
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash 7cc0149 021/316: [#99] Add -take-last and -drop-last |
Date: |
Mon, 15 Feb 2021 15:57:17 -0500 (EST) |
branch: externals/dash
commit 7cc01498a27d63ff4e0f3cd19ce7a53397fb533d
Author: Matus Goljer <matus.goljer@gmail.com>
Commit: Matus Goljer <matus.goljer@gmail.com>
[#99] Add -take-last and -drop-last
---
README.md | 29 +++++++++++++++++++++++++++++
dash.el | 22 ++++++++++++++++++++--
dev/examples.el | 12 ++++++++++++
3 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 3f54228..1338ddc 100644
--- a/README.md
+++ b/README.md
@@ -99,7 +99,9 @@ Functions returning a sublist of the original list.
* [-non-nil](#-non-nil-list) `(list)`
* [-slice](#-slice-list-from-optional-to-step) `(list from &optional to step)`
* [-take](#-take-n-list) `(n list)`
+* [-take-last](#-take-last-n-list) `(n list)`
* [-drop](#-drop-n-list) `(n list)`
+* [-drop-last](#-drop-last-n-list) `(n list)`
* [-take-while](#-take-while-pred-list) `(pred list)`
* [-drop-while](#-drop-while-pred-list) `(pred list)`
* [-select-by-indices](#-select-by-indices-indices-list) `(indices list)`
@@ -535,20 +537,47 @@ section is returned. Defaults to 1.
Return a new list of the first `n` items in `list`, or all items if there are
fewer than `n`.
+See also: [`-take-last`](#-take-last-n-list)
+
```el
(-take 3 '(1 2 3 4 5)) ;; => '(1 2 3)
(-take 17 '(1 2 3 4 5)) ;; => '(1 2 3 4 5)
```
+#### -take-last `(n list)`
+
+Return the last `n` items of `list` in order.
+
+See also: [`-take`](#-take-n-list)
+
+```el
+(-take-last 3 '(1 2 3 4 5)) ;; => '(3 4 5)
+(-take-last 17 '(1 2 3 4 5)) ;; => '(1 2 3 4 5)
+(-take-last 1 '(1 2 3 4 5)) ;; => '(5)
+```
+
#### -drop `(n list)`
Return the tail of `list` without the first `n` items.
+See also: [`-drop-last`](#-drop-last-n-list)
+
```el
(-drop 3 '(1 2 3 4 5)) ;; => '(4 5)
(-drop 17 '(1 2 3 4 5)) ;; => '()
```
+#### -drop-last `(n list)`
+
+Remove the last `n` items of `list` and return a copy.
+
+See also: [`-drop`](#-drop-n-list)
+
+```el
+(-drop-last 3 '(1 2 3 4 5)) ;; => '(1 2)
+(-drop-last 17 '(1 2 3 4 5)) ;; => '()
+```
+
#### -take-while `(pred list)`
Return a new list of successive items from `list` while (`pred` item) returns
a non-nil value.
diff --git a/dash.el b/dash.el
index 87983fd..41651a1 100644
--- a/dash.el
+++ b/dash.el
@@ -673,7 +673,9 @@ section is returned. Defaults to 1."
(nreverse new-list)))
(defun -take (n list)
- "Return a new list of the first N items in LIST, or all items if there are
fewer than N."
+ "Return a new list of the first N items in LIST, or all items if there are
fewer than N.
+
+See also: `-take-last'"
(let (result)
(--dotimes n
(when list
@@ -681,7 +683,23 @@ section is returned. Defaults to 1."
(!cdr list)))
(nreverse result)))
-(defalias '-drop 'nthcdr "Return the tail of LIST without the first N items.")
+(defun -take-last (n list)
+ "Return the last N items of LIST in order.
+
+See also: `-take'"
+ (copy-sequence (last list n)))
+
+(defalias '-drop 'nthcdr
+ "Return the tail of LIST without the first N items.
+
+See also: `-drop-last'")
+
+(defun -drop-last (n list)
+ "Remove the last N items of LIST and return a copy.
+
+See also: `-drop'"
+ ;; No alias because we don't want magic optional argument
+ (butlast list n))
(defmacro --take-while (form list)
"Anaphoric form of `-take-while'."
diff --git a/dev/examples.el b/dev/examples.el
index 8bf6a2e..92f8861 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -168,10 +168,22 @@ new list."
(-take 3 '(1 2 3 4 5)) => '(1 2 3)
(-take 17 '(1 2 3 4 5)) => '(1 2 3 4 5))
+ (defexamples -take-last
+ (-take-last 3 '(1 2 3 4 5)) => '(3 4 5)
+ (-take-last 17 '(1 2 3 4 5)) => '(1 2 3 4 5)
+ (-take-last 1 '(1 2 3 4 5)) => '(5)
+ (let ((l '(1 2 3 4 5)))
+ (setcar (-take-last 2 l) 1)
+ l) => '(1 2 3 4 5))
+
(defexamples -drop
(-drop 3 '(1 2 3 4 5)) => '(4 5)
(-drop 17 '(1 2 3 4 5)) => '())
+ (defexamples -drop-last
+ (-drop-last 3 '(1 2 3 4 5)) => '(1 2)
+ (-drop-last 17 '(1 2 3 4 5)) => '())
+
(defexamples -take-while
(-take-while 'even? '(1 2 3 4)) => '()
(-take-while 'even? '(2 4 5 6)) => '(2 4)
- [elpa] externals/dash 0d84c0f 009/316: Merge pull request #167 from syohex/update-url, (continued)
- [elpa] externals/dash 0d84c0f 009/316: Merge pull request #167 from syohex/update-url, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 8a46d3c 013/316: [#170] Add a note about -keep on -filter., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 81b15c5 006/316: Fix: The upcoming breaking change is 3.0, not 2.0, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 6484fb5 012/316: Merge pull request #168 from camsaul/patch-2, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0272e8b 017/316: [Fix #158] -map-last does not modify input list., ELPA Syncer, 2021/02/15
- [elpa] externals/dash 1fce650 019/316: Add `-each-indexed` and an anaphoric equivalent (#178), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 7b2845a 011/316: Fix broken GH profile link in README, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 096f244 018/316: --remove-last does not modify input list #158, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 3e7163a 020/316: [#99] Use butlast to implement -butlast, ELPA Syncer, 2021/02/15
- [elpa] externals/dash eef3bb0 023/316: Document -doto macro in the README (#181), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 7cc0149 021/316: [#99] Add -take-last and -drop-last,
ELPA Syncer <=
- [elpa] externals/dash 6d8abc7 022/316: Add -doto macro (like Clojure's doto) (#177), ELPA Syncer, 2021/02/15
- [elpa] externals/dash f1c60c4 034/316: Merge pull request #193 from GuiltyDolphin/fix-map-when-typo, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 15f384d 025/316: Copyedit: argument name consistency (#187), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 937f8a1 026/316: Update documentation, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 012b3bc 024/316: Docstrings grammar fixes (#186), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 6ded2f2 014/316: Add 'see also' to `-find-index` and `-find-last-index`., ELPA Syncer, 2021/02/15
- [elpa] externals/dash e680ad0 015/316: Merge pull request #173 from Wilfred/master, ELPA Syncer, 2021/02/15
- [elpa] externals/dash a10fb6b 028/316: Add -each-indexed keyword to font-lock, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 502be58 029/316: Make -each-indexed indent like -each, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 4ae329a 032/316: Release 2.13.0, ELPA Syncer, 2021/02/15