emacs-elpa-diffs
[Top][All Lists]
Advanced

[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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]