Add !split-at

master
Magnar Sveen 14 years ago
parent 8c75026576
commit ec835e4418
  1. 10
      README.md
  2. 5
      bang.el
  3. 4
      examples.el

@ -24,6 +24,7 @@ Or you can just dump `bang.el` in your load path somewhere.
* [!drop](#drop-n-list) `(n list)` * [!drop](#drop-n-list) `(n list)`
* [!take-while](#take-while-fn-list) `(fn list)` * [!take-while](#take-while-fn-list) `(fn list)`
* [!drop-while](#drop-while-fn-list) `(fn list)` * [!drop-while](#drop-while-fn-list) `(fn list)`
* [!split-at](#split-at-n-list) `(n list)`
* [!split-with](#split-with-fn-list) `(fn list)` * [!split-with](#split-with-fn-list) `(fn list)`
* [!interpose](#interpose-sep-list) `(sep list)` * [!interpose](#interpose-sep-list) `(sep list)`
* [!replace-where](#replace-where-pred-rep-list) `(pred rep list)` * [!replace-where](#replace-where-pred-rep-list) `(pred rep list)`
@ -205,6 +206,15 @@ Returns the tail of `list` starting from the first item for which (`fn` item) re
(!!drop-while (< it 4) '(1 2 3 4 3 2 1)) ;; => '(4 3 2 1) (!!drop-while (< it 4) '(1 2 3 4 3 2 1)) ;; => '(4 3 2 1)
``` ```
### !split-at `(n list)`
Returns a list of ((!take `n` `list`) (!drop `n` `list`))
```cl
(!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)
```
### !split-with `(fn list)` ### !split-with `(fn list)`
Returns a list of ((!take-while `fn` `list`) (!drop-while `fn` `list`)) Returns a list of ((!take-while `fn` `list`) (!drop-while `fn` `list`))

@ -187,6 +187,11 @@ Thus function FN should return a collection."
"Returns the tail of LIST starting from the first item for which (FN item) returns nil." "Returns the tail of LIST starting from the first item for which (FN item) returns nil."
(!!drop-while (funcall fn it) list)) (!!drop-while (funcall fn it) list))
(defun !split-at (n list)
"Returns a list of ((!take N LIST) (!drop N LIST))"
(list (!take n list)
(!drop n list)))
(defmacro !!split-with (form list) (defmacro !!split-with (form list)
"Anaphoric form of `!split-with'." "Anaphoric form of `!split-with'."
`(list (!!take-while ,form ,list) `(list (!!take-while ,form ,list)

@ -76,6 +76,10 @@
(!drop-while 'even? '(2 4 5 6)) => '(5 6) (!drop-while 'even? '(2 4 5 6)) => '(5 6)
(!!drop-while (< it 4) '(1 2 3 4 3 2 1)) => '(4 3 2 1)) (!!drop-while (< it 4) '(1 2 3 4 3 2 1)) => '(4 3 2 1))
(defexamples !split-at
(!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 !split-with (defexamples !split-with
(!split-with 'even? '(1 2 3 4)) => '(() (1 2 3 4)) (!split-with 'even? '(1 2 3 4)) => '(() (1 2 3 4))
(!split-with 'even? '(2 4 5 6)) => '((2 4) (5 6)) (!split-with 'even? '(2 4 5 6)) => '((2 4) (5 6))

Loading…
Cancel
Save