master
Magnar Sveen 14 years ago
parent 123eaaa6cf
commit b9b6330216
  1. 10
      README.md
  2. 9
      bang.el
  3. 4
      examples.el

@ -20,6 +20,7 @@ Or you can just dump `bang.el` in your load path somewhere.
* [!keep](#keep-fn-list) `(fn list)`
* [!concat](#concat-rest-lists) `(&rest lists)`
* [!mapcat](#mapcat-fn-list) `(fn list)`
* [!take](#take-n-list) `(n list)`
* [!take-while](#take-while-fn-list) `(fn list)`
* [!drop-while](#drop-while-fn-list) `(fn list)`
* [!split-with](#split-with-fn-list) `(fn list)`
@ -165,6 +166,15 @@ Thus function `fn` should return a collection.
(!!mapcat (list 0 it) '(1 2 3)) ;; => '(0 1 0 2 0 3)
```
### !take `(n list)`
Returns a new list of the first `n` items in `list`, or all items if there are fewer than `n`.
```cl
(!take 3 '(1 2 3 4 5)) ;; => '(1 2 3)
(!take 17 '(1 2 3 4 5)) ;; => '(1 2 3 4 5)
```
### !take-while `(fn list)`
Returns a new list of successive items from `list` while (`fn` item) returns a non-nil value.

@ -144,6 +144,15 @@ the supplied LISTS."
Thus function FN should return a collection."
(!!mapcat (funcall fn it) list))
(defun !take (n list)
"Returns a new list of the first N items in LIST, or all items if there are fewer than N."
(let (result)
(while (and list (> n 0))
(setq result (cons (car list) result))
(setq list (cdr list))
(setq n (1- n)))
(nreverse result)))
(defmacro !!take-while (form list)
"Anaphoric form of `!take-while'."
(let ((l (make-symbol "list"))

@ -58,6 +58,10 @@
(!mapcat (lambda (item) (list 0 item)) '(1 2 3)) => '(0 1 0 2 0 3)
(!!mapcat (list 0 it) '(1 2 3)) => '(0 1 0 2 0 3))
(defexamples !take
(!take 3 '(1 2 3 4 5)) => '(1 2 3)
(!take 17 '(1 2 3 4 5)) => '(1 2 3 4 5))
(defexamples !take-while
(!take-while 'even? '(1 2 3 4)) => '()
(!take-while 'even? '(2 4 5 6)) => '(2 4)

Loading…
Cancel
Save