Add `-find-last-index`

master
Matus Goljer 12 years ago
parent e6cae0bee7
commit 3eb91fec0e
  1. 13
      README.md
  2. 12
      dash.el
  3. 5
      dev/examples.el

@ -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

@ -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"

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

Loading…
Cancel
Save