Merge pull request #28 from shosti/master

Add -insert-at
master
Magnar Sveen 13 years ago
commit 0ff070bebb
  1. 10
      README.md
  2. 6
      dash.el
  3. 4
      dev/examples.el

@ -39,6 +39,7 @@ Or you can just dump `dash.el` in your load path somewhere.
* [-take-while](#-take-while-pred-list) `(pred list)`
* [-drop-while](#-drop-while-pred-list) `(pred list)`
* [-split-at](#-split-at-n-list) `(n list)`
* [-insert-at](#-insert-at-n-x-list) `(n x list)`
* [-split-with](#-split-with-pred-list) `(pred list)`
* [-separate](#-separate-pred-list) `(pred list)`
* [-partition](#-partition-n-list) `(n list)`
@ -392,6 +393,15 @@ Returns a list of ((-take `n` `list`) (-drop `n` `list`)), in no more than one p
(-split-at 17 '(1 2 3 4 5)) ;; => '((1 2 3 4 5) nil)
```
### -insert-at `(n x list)`
Returns a list with `x` inserted into `list` at position `n`.
```cl
(-insert-at 1 'x '(a b c)) ;; => '(a x b c)
(-insert-at 12 'x '(a b c)) ;; => '(a b c x)
```
### -split-with `(pred list)`
Returns a list of ((-take-while `pred` `list`) (-drop-while `pred` `list`)), in no more than one pass through the list.

@ -411,6 +411,11 @@ FROM or TO may be negative."
(!cdr list)))
(list (nreverse result) list)))
(defun -insert-at (n x list)
"Returns a list with X inserted into LIST at position N."
(let ((split-list (-split-at n list)))
(append (car split-list) (cons x (cadr split-list)))))
(defmacro --split-with (pred list)
"Anaphoric form of `-split-with'."
(let ((l (make-symbol "list"))
@ -843,6 +848,7 @@ Returns nil if N is less than 1."
"--drop-while"
"-drop-while"
"-split-at"
"-insert-at"
"--split-with"
"-split-with"
"-partition"

@ -150,6 +150,10 @@
(-split-at 3 '(1 2 3 4 5)) => '((1 2 3) (4 5))
(-split-at 17 '(1 2 3 4 5)) => '((1 2 3 4 5) nil))
(defexamples -insert-at
(-insert-at 1 'x '(a b c)) => '(a x b c)
(-insert-at 12 'x '(a b c)) => '(a b c x))
(defexamples -split-with
(-split-with 'even? '(1 2 3 4)) => '(() (1 2 3 4))
(-split-with 'even? '(2 4 5 6)) => '((2 4) (5 6))

Loading…
Cancel
Save