Add -butlast

master
Magnar Sveen 12 years ago
parent f8873a0dd8
commit f257fb907e
  1. 11
      README.md
  2. 9
      dash.el
  3. 6
      dev/examples.el

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

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

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

Loading…
Cancel
Save