[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 3eb91fe 280/439: Add `-find-last-index`
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 3eb91fe 280/439: Add `-find-last-index` |
Date: |
Tue, 04 Aug 2015 20:29:02 +0000 |
branch: externals/dash
commit 3eb91fec0e645e847fe6a6fb8dba04e8e4116a95
Author: Matus Goljer <address@hidden>
Commit: Matus Goljer <address@hidden>
Add `-find-last-index`
---
README.md | 13 +++++++++++++
dash.el | 12 ++++++++++++
dev/examples.el | 5 +++++
3 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 4ee7cde..f52d46d 100644
--- a/README.md
+++ b/README.md
@@ -99,6 +99,7 @@ Include this in your emacs settings to get syntax
highlighting:
* [-elem-index](#-elem-index-elem-list) `(elem list)`
* [-elem-indices](#-elem-indices-elem-list) `(elem list)`
* [-find-index](#-find-index-pred-list) `(pred list)`
+* [-find-last-index](#-find-last-index-pred-list) `(pred list)`
* [-find-indices](#-find-indices-pred-list) `(pred list)`
* [-select-by-indices](#-select-by-indices-indices-list) `(indices list)`
* [-grade-up](#-grade-up-comparator-list) `(comparator list)`
@@ -784,6 +785,18 @@ there is no such element.
(-find-index (-partial 'string-lessp "baz") '("bar" "foo" "baz")) ;; => 1
```
+#### -find-last-index `(pred list)`
+
+Take a predicate `pred` and a `list` and return the index of the
+last element in the list satisfying the predicate, or nil if
+there is no such element.
+
+```cl
+(-find-last-index 'even? '(2 4 1 6 3 3 5 8)) ;; => 7
+(--find-last-index (< 5 it) '(2 7 1 6 3 8 5 2)) ;; => 5
+(-find-last-index (-partial 'string-lessp "baz") '("q" "foo" "baz")) ;; => 1
+```
+
#### -find-indices `(pred list)`
Return the indices of all elements in `list` satisfying the
diff --git a/dash.el b/dash.el
index e6013ce..e1f6049 100644
--- a/dash.el
+++ b/dash.el
@@ -781,6 +781,16 @@ there is no such element."
"Anaphoric version of `-find-index'."
`(-find-index (lambda (it) ,form) ,list))
+(defun -find-last-index (pred list)
+ "Take a predicate PRED and a LIST and return the index of the
+last element in the list satisfying the predicate, or nil if
+there is no such element."
+ (-last-item (-find-indices pred list)))
+
+(defmacro --find-last-index (form list)
+ "Anaphoric version of `-find-last-index'."
+ `(-find-last-index (lambda (it) ,form) ,list))
+
(defun -select-by-indices (indices list)
"Return a list whose elements are elements from LIST selected
as `(nth i list)` for all i from INDICES."
@@ -1291,6 +1301,8 @@ structure such as plist or alist."
"--find-indices"
"-find-index"
"--find-index"
+ "-find-last-index"
+ "--find-last-index"
"-select-by-indices"
"-grade-up"
"-grade-down"
diff --git a/dev/examples.el b/dev/examples.el
index 88e4f3d..c0ae5bf 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -303,6 +303,11 @@
(--find-index (< 5 it) '(2 4 1 6 3 3 5 8)) => 3
(-find-index (-partial 'string-lessp "baz") '("bar" "foo" "baz")) => 1)
+ (defexamples -find-last-index
+ (-find-last-index 'even? '(2 4 1 6 3 3 5 8)) => 7
+ (--find-last-index (< 5 it) '(2 7 1 6 3 8 5 2)) => 5
+ (-find-last-index (-partial 'string-lessp "baz") '("q" "foo" "baz")) => 1)
+
(defexamples -find-indices
(-find-indices 'even? '(2 4 1 6 3 3 5 8)) => '(0 1 3 7)
(--find-indices (< 5 it) '(2 4 1 6 3 3 5 8)) => '(3 7)
- [elpa] externals/dash 396d6ac 271/439: Declare macro before using it., (continued)
- [elpa] externals/dash 396d6ac 271/439: Declare macro before using it., Phillip Lord, 2015/08/04
- [elpa] externals/dash 4818368 272/439: Release 2.4.3, Phillip Lord, 2015/08/04
- [elpa] externals/dash 25be31a 270/439: Release 2.4.2, Phillip Lord, 2015/08/04
- [elpa] externals/dash 386ec0a 273/439: Add -same-items? function., Phillip Lord, 2015/08/04
- [elpa] externals/dash adaeff7 274/439: Merge pull request #65 from rejeep/same-items-predicate, Phillip Lord, 2015/08/04
- [elpa] externals/dash 960b05f 276/439: Set -each, -each-while and -dotimes indent levels to 1., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6abc35a 277/439: Merge pull request #66 from rejeep/each-indent-level, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5d25ed2 275/439: Release 2.5.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 930b390 278/439: Add -list function., Phillip Lord, 2015/08/04
- [elpa] externals/dash e6cae0b 279/439: Merge pull request #68 from rejeep/list-function, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3eb91fe 280/439: Add `-find-last-index`,
Phillip Lord <=
- [elpa] externals/dash 7eb8307 283/439: Merge pull request #71 from Fuco1/find-last-index, Phillip Lord, 2015/08/04
- [elpa] externals/dash 79c23bb 282/439: Merge pull request #70 from Fuco1/debug-decl, Phillip Lord, 2015/08/04
- [elpa] externals/dash b201f0c 281/439: Add debug declarations and move indent declarations into `declare`, Phillip Lord, 2015/08/04
- [elpa] externals/dash 38cd4d2 284/439: Fix fontification when there are dashes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4098ea0 285/439: Merge pull request #74 from YoungFrog/dashfontifix, Phillip Lord, 2015/08/04
- [elpa] externals/dash b075846 287/439: Add -iterate, -unfold, Phillip Lord, 2015/08/04
- [elpa] externals/dash f96196a 289/439: Merge pull request #75 from Fuco1/prefix, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6bdcfa5 286/439: Add -split-on, -split-when, Phillip Lord, 2015/08/04
- [elpa] externals/dash b44140a 288/439: Add -is-prefix/suffix/infix-p, Phillip Lord, 2015/08/04
- [elpa] externals/dash abff641 290/439: Merge pull request #76 from Fuco1/unfold, Phillip Lord, 2015/08/04