[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 6238f8f 077/426: Add !split-with
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 6238f8f 077/426: Add !split-with |
Date: |
Tue, 04 Aug 2015 19:36:49 +0000 |
branch: externals/dash
commit 6238f8fbbd956dfc58d861a4efced68cc069d75b
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Add !split-with
---
README.md | 11 +++++++++++
bang.el | 9 +++++++++
examples.el | 5 +++++
3 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 0370383..335ea17 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,7 @@ Or you can just dump `bang.el` in your load path somewhere.
* [!mapcat](#mapcat-fn-list) `(fn 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)`
* [!interpose](#interpose-sep-list) `(sep list)`
* [!replace-where](#replace-where-pred-rep-list) `(pred rep list)`
* [!first](#first-fn-list) `(fn list)`
@@ -184,6 +185,16 @@ 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)
```
+### !split-with `(fn list)`
+
+Returns a list of ((!take-while `fn` `list`) (!drop-while `fn` `list`))
+
+```cl
+(!split-with 'even? '(1 2 3 4)) ;; => '(nil (1 2 3 4))
+(!split-with 'even? '(2 4 5 6)) ;; => '((2 4) (5 6))
+(!!split-with (< it 4) '(1 2 3 4 3 2 1)) ;; => '((1 2 3) (4 3 2 1))
+```
+
### !interpose `(sep list)`
Returns a new list of all elements in `list` separated by `sep`.
diff --git a/bang.el b/bang.el
index 0cd4c0f..2b96b29 100644
--- a/bang.el
+++ b/bang.el
@@ -171,6 +171,15 @@ Thus function FN should return a collection."
"Returns the tail of LIST starting from the first item for which (FN item)
returns nil."
(!!drop-while (funcall fn it) list))
+(defmacro !!split-with (form list)
+ "Anaphoric form of `!split-with'."
+ `(list (!!take-while ,form ,list)
+ (!!drop-while ,form ,list)))
+
+(defun !split-with (fn list)
+ "Returns a list of ((!take-while FN LIST) (!drop-while FN LIST))"
+ (!!split-with (funcall fn it) list))
+
(defun !interpose (sep list)
"Returns a new list of all elements in LIST separated by SEP."
(let (result)
diff --git a/examples.el b/examples.el
index c2578b3..8d4283d 100644
--- a/examples.el
+++ b/examples.el
@@ -68,6 +68,11 @@
(!drop-while 'even? '(2 4 5 6)) => '(5 6)
(!!drop-while (< it 4) '(1 2 3 4 3 2 1)) => '(4 3 2 1))
+(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))
+ (!!split-with (< it 4) '(1 2 3 4 3 2 1)) => '((1 2 3) (4 3 2 1)))
+
(defexamples !interpose
(!interpose "-" '()) => '()
(!interpose "-" '("a")) => '("a")
- [elpa] externals/dash 1a7ad85 065/426: Mention Melpa in README, (continued)
- [elpa] externals/dash 1a7ad85 065/426: Mention Melpa in README, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6be4c03 058/426: !first, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0991c29 057/426: Added some common aliases, Phillip Lord, 2015/08/04
- [elpa] externals/dash ca3eea7 070/426: Fix examples-to-docs to support documenting macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash a6323eb 059/426: Add some tests that verify that the lists are evaled by the anaphoric macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash b29a5bb 071/426: Use make-symbol in macros to avoid names clashing., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6520496 060/426: First release, remove warning., Phillip Lord, 2015/08/04
- [elpa] externals/dash 8bd82c7 051/426: Show empty lists as '() instead of nil in docs., Phillip Lord, 2015/08/04
- [elpa] externals/dash 66ffaa6 072/426: Add !interpose, Phillip Lord, 2015/08/04
- [elpa] externals/dash ec6a85f 074/426: Add threading macro !!-> with `it` as placeholder., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6238f8f 077/426: Add !split-with,
Phillip Lord <=
- [elpa] externals/dash 4e76865 075/426: Add !take-while, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3802890 082/426: Simplify !concat, Phillip Lord, 2015/08/04
- [elpa] externals/dash ec835e4 081/426: Add !split-at, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0dab44c 084/426: Add -flatten, Phillip Lord, 2015/08/04
- [elpa] externals/dash 047eeea 066/426: Run tests on Emacs 24., Phillip Lord, 2015/08/04
- [elpa] externals/dash 9410f7e 073/426: Add !replace-where, Phillip Lord, 2015/08/04
- [elpa] externals/dash 123eaaa 078/426: Docs: Refer to !replace-where from !!replace-where., Phillip Lord, 2015/08/04
- [elpa] externals/dash 70488c2 063/426: Add !rpartial, Phillip Lord, 2015/08/04
- [elpa] externals/dash 82a12a2 076/426: Add !drop-while, Phillip Lord, 2015/08/04
- [elpa] externals/dash fea1aa3 086/426: Add -interleave, Phillip Lord, 2015/08/04