[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash f257fb9 328/426: Add -butlast
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash f257fb9 328/426: Add -butlast |
Date: |
Tue, 04 Aug 2015 19:38:38 +0000 |
branch: externals/dash
commit f257fb907ecea0ca79df7c8599cfb5df0c30dff9
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Add -butlast
---
README.md | 11 +++++++++++
dash.el | 9 +++++++++
dev/examples.el | 6 ++++++
3 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 5f0f46a..e8f7390 100644
--- a/README.md
+++ b/README.md
@@ -181,6 +181,7 @@ Other list functions not fit to be classified elsewhere.
* [-last](#-last-pred-list) `(pred list)`
* [-first-item](#-first-item-list) `(list)`
* [-last-item](#-last-item-list) `(list)`
+* [-butlast](#-butlast-list) `(list)`
* [-sort](#-sort-comparator-list) `(comparator list)`
* [-list](#-list-rest-args) `(&rest args)`
@@ -1410,6 +1411,16 @@ Return the last item of `list`, or nil on an empty list.
(-last-item nil) ;; => nil
```
+#### -butlast `(list)`
+
+Return a list of all items in list except for the last.
+
+```cl
+(-butlast '(1 2 3)) ;; => '(1 2)
+(-butlast '(1 2)) ;; => '(1)
+(-butlast '(1)) ;; => nil
+```
+
#### -sort `(comparator list)`
Sort `list`, stably, comparing elements using `comparator`.
diff --git a/dash.el b/dash.el
index 22f977b..8928009 100644
--- a/dash.el
+++ b/dash.el
@@ -399,6 +399,14 @@ Alias: `-find'"
"Return the last item of LIST, or nil on an empty list."
(car (last list)))
+(defun -butlast (list)
+ "Return a list of all items in list except for the last."
+ (let (result)
+ (while (cdr list)
+ (!cons (car list) result)
+ (!cdr list))
+ (nreverse result)))
+
(defmacro --count (pred list)
"Anaphoric form of `-count'."
(declare (debug (form form)))
@@ -1561,6 +1569,7 @@ structure such as plist or alist."
"--last"
"-first-item"
"-last-item"
+ "-butlast"
"-count"
"--count"
"-any?"
diff --git a/dev/examples.el b/dev/examples.el
index 945cfac..26ed0e4 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -549,6 +549,12 @@ new list."
(-last-item '(1 2 3)) => 3
(-last-item nil) => nil)
+ (defexamples -butlast
+ (-butlast '(1 2 3)) => '(1 2)
+ (-butlast '(1 2)) => '(1)
+ (-butlast '(1)) => nil
+ (-butlast nil) => nil)
+
(defexamples -sort
(-sort '< '(3 1 2)) => '(1 2 3)
(-sort '> '(3 1 2)) => '(3 2 1)
- [elpa] externals/dash d948086 315/426: Add -iteratefn, (continued)
- [elpa] externals/dash d948086 315/426: Add -iteratefn, Phillip Lord, 2015/08/04
- [elpa] externals/dash a09a4b2 318/426: Add code markup for docstrings and fix erroneous whitespace in docstring, Phillip Lord, 2015/08/04
- [elpa] externals/dash 38307e3 223/426: Partition docs, Phillip Lord, 2015/08/04
- [elpa] externals/dash f3b0a55 321/426: Change -predicate-p examples to -predicate? to maintain consistency, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7e4adb5 319/426: Add missing keywords to highlight list, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2ecc073 316/426: Reorder the partition examples to follow more logical order, add tests, Phillip Lord, 2015/08/04
- [elpa] externals/dash eea928a 320/426: Add -replace, Phillip Lord, 2015/08/04
- [elpa] externals/dash d9879e9 329/426: Release 2.8.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash f8873a0 327/426: Update readme-template with changes from last release, Phillip Lord, 2015/08/04
- [elpa] externals/dash 25c114c 330/426: Implementing a shallow copy counterpart to -clone., Phillip Lord, 2015/08/04
- [elpa] externals/dash f257fb9 328/426: Add -butlast,
Phillip Lord <=
- [elpa] externals/dash 174747e 323/426: Add -splice and -splice-list, Phillip Lord, 2015/08/04
- [elpa] externals/dash ab99be6 335/426: Add -fix, Phillip Lord, 2015/08/04
- [elpa] externals/dash b1e585d 337/426: Update copyright notice, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3adad97 334/426: Add -non-nil, Phillip Lord, 2015/08/04
- [elpa] externals/dash 166bccd 333/426: Add -tree-map-nodes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 05fa92f 342/426: [-let] Transpose nreverse/flatten, Phillip Lord, 2015/08/04
- [elpa] externals/dash f0831d3 339/426: Add -lambda, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9ebcce6 325/426: Add some niceties to font-locking of examples, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6fc652d 331/426: Merge pull request #95 from Wilfred/shallow-copy-function, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5637bd6 322/426: Add alias from -find to -first, Phillip Lord, 2015/08/04