[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash a40fc00 162/439: Merge pull request #23 from Fuco1
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash a40fc00 162/439: Merge pull request #23 from Fuco1/last |
Date: |
Tue, 04 Aug 2015 20:27:28 +0000 |
branch: externals/dash
commit a40fc004526cc602c38879270739e578e11e33a3
Merge: d7174ed a559a80
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Merge pull request #23 from Fuco1/last
Added -last
---
README.md | 12 ++++++++++++
dash.el | 12 ++++++++++++
dev/examples.el | 5 +++++
3 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 845ab17..9d47f44 100644
--- a/README.md
+++ b/README.md
@@ -51,6 +51,7 @@ Or you can just dump `dash.el` in your load path somewhere.
* [-zip-with](#-zip-with-fn-list1-list2) `(fn list1 list2)`
* [-zip](#-zip-list1-list2) `(list1 list2)`
* [-first](#-first-pred-list) `(pred list)`
+* [-last](#-last-pred-list) `(pred list)`
* [-union](#-union-list-list2) `(list list2)`
* [-difference](#-difference-list-list2) `(list list2)`
* [-intersection](#-intersection-list-list2) `(list list2)`
@@ -199,6 +200,7 @@ Takes a nested list `l` and returns its contents as a
single, flat list.
```cl
(-flatten '((1))) ;; => '(1)
(-flatten '((1 (2 3) (((4 (5))))))) ;; => '(1 2 3 4 5)
+(-flatten '(1 2 (3 . 4))) ;; => '(1 2 (3 . 4))
```
### -concat `(&rest lists)`
@@ -526,6 +528,16 @@ To get the first item in the list no questions asked, use
`car`.
(--first (> it 2) '(1 2 3)) ;; => 3
```
+### -last `(pred list)`
+
+Return the last x in `list` where (`pred` x) is non-nil, else nil.
+
+```cl
+(-last 'even? '(1 2 3 4 5 6 3 3 3)) ;; => 6
+(-last 'even? '(1 3 7 5 9)) ;; => nil
+(--last (> (length it) 3) '("a" "looong" "word" "and" "short" "one")) ;; =>
"short"
+```
+
### -union `(list list2)`
Return a new list containing the elements of `list1` and elements of `list2`
that are not in `list1`.
diff --git a/dash.el b/dash.el
index 6ca2fea..1626476 100644
--- a/dash.el
+++ b/dash.el
@@ -250,6 +250,18 @@ a dotted list."
To get the first item in the list no questions asked, use `car'."
(--first (funcall pred it) list))
+(defmacro --last (form list)
+ "Anaphoric form of `-last'."
+ (let ((n (make-symbol "needle")))
+ `(let (,n)
+ (--each ,list
+ (when ,form (setq ,n it)))
+ ,n)))
+
+(defun -last (pred list)
+ "Return the last x in LIST where (PRED x) is non-nil, else nil."
+ (--last (funcall pred it) list))
+
(defmacro --count (pred list)
"Anaphoric form of `-count'."
(let ((r (make-symbol "result")))
diff --git a/dev/examples.el b/dev/examples.el
index caa7f5c..b6d9045 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -211,6 +211,11 @@
(-first 'even? '(1 3 5)) => nil
(--first (> it 2) '(1 2 3)) => 3)
+(defexamples -last
+ (-last 'even? '(1 2 3 4 5 6 3 3 3)) => 6
+ (-last 'even? '(1 3 7 5 9)) => nil
+ (--last (> (length it) 3) '("a" "looong" "word" "and" "short" "one")) =>
"short")
+
(defexamples -union
(-union '(1 2 3) '(3 4 5)) => '(1 2 3 4 5)
(-union '(1 2 3 4) '()) => '(1 2 3 4)
- [elpa] externals/dash cc33c2f 153/439: Stop integration tests for Emacs 23, (continued)
- [elpa] externals/dash cc33c2f 153/439: Stop integration tests for Emacs 23, Phillip Lord, 2015/08/04
- [elpa] externals/dash c218e9f 150/439: -split-at/with now makes just one pass over list, Phillip Lord, 2015/08/04
- [elpa] externals/dash adfafcb 152/439: Add -partition-by-header, Phillip Lord, 2015/08/04
- [elpa] externals/dash a4b70f9 154/439: [magnars/dash.el#18] implementing -slice, Phillip Lord, 2015/08/04
- [elpa] externals/dash dac28b0 155/439: Merge pull request #19 from Wilfred/master, Phillip Lord, 2015/08/04
- [elpa] externals/dash bd942e1 158/439: inhibit dev from being added to the load-path, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0351ca3 156/439: Add Wilfred Hughes to list of contributors., Phillip Lord, 2015/08/04
- [elpa] externals/dash 2451f99 159/439: Merge pull request #20 from tarsius/master, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6ffdc93 157/439: Release 1.1.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash a559a80 161/439: Added -last, Phillip Lord, 2015/08/04
- [elpa] externals/dash a40fc00 162/439: Merge pull request #23 from Fuco1/last,
Phillip Lord <=
- [elpa] externals/dash d7174ed 160/439: Handle cons-cells properly in -flatten, Phillip Lord, 2015/08/04
- [elpa] externals/dash a1b04d8 163/439: Less implementation specific docs for -mapcat, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9371ce4 164/439: Don't use the word collection when meaning list, Phillip Lord, 2015/08/04
- [elpa] externals/dash c3dc883 166/439: Merge pull request #26 from shosti/when-if-let, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6420bf8 167/439: Add Emanuel Evans to list of contributors, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1396102 165/439: Add -when-let and -if-let macros, Phillip Lord, 2015/08/04
- [elpa] externals/dash 30ac13b 168/439: Add -insert-at (closes #27), Phillip Lord, 2015/08/04
- [elpa] externals/dash d5c124d 170/439: Update @shosti's list of contributions., Phillip Lord, 2015/08/04
- [elpa] externals/dash 1754ae2 171/439: Typo, Phillip Lord, 2015/08/04
- [elpa] externals/dash 79e3b92 172/439: Fix -when-let and -if-let docstrings, Phillip Lord, 2015/08/04