[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash c025efb 122/439: Add -separate (thanks @Fuco1)
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash c025efb 122/439: Add -separate (thanks @Fuco1) |
Date: |
Tue, 04 Aug 2015 20:27:05 +0000 |
branch: externals/dash
commit c025efb9fc000c145996e22abb7bf92607ea756b
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Add -separate (thanks @Fuco1)
---
README.md | 11 +++++++++++
dash.el | 12 ++++++++++++
examples.el | 5 +++++
3 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 242b532..0b613f3 100644
--- a/README.md
+++ b/README.md
@@ -35,6 +35,7 @@ Or you can just dump `dash.el` in your load path somewhere.
* [-drop-while](#-drop-while-pred-list) `(pred list)`
* [-split-at](#-split-at-n-list) `(n list)`
* [-split-with](#-split-with-pred-list) `(pred list)`
+* [-separate](#-separate-pred-list) `(pred list)`
* [-partition](#-partition-n-list) `(n list)`
* [-partition-all](#-partition-all-n-list) `(n list)`
* [-partition-by](#-partition-by-fn-list) `(fn list)`
@@ -331,6 +332,16 @@ Returns a list of ((-take-while `pred` `list`)
(-drop-while `pred` `list`))
(--split-with (< it 4) '(1 2 3 4 3 2 1)) ;; => '((1 2 3) (4 3 2 1))
```
+### -separate `(pred list)`
+
+Returns a list of ((-filter `pred` `list`) (-remove `pred` `list`)).
+
+```cl
+(-separate (lambda (num) (= 0 (% num 2))) '(1 2 3 4 5 6 7)) ;; => '((2 4 6) (1
3 5 7))
+(--separate (< it 5) '(3 7 5 9 3 2 1 4 6)) ;; => '((3 3 2 1 4) (7 5 9 6))
+(-separate 'cdr '((1 2) (1) (1 2 3) (4))) ;; => '(((1 2) (1 2 3)) ((1) (4)))
+```
+
### -partition `(n list)`
Returns a new list with the items in `list` grouped into `n-`sized sublists.
diff --git a/dash.el b/dash.el
index 7933f53..3b870f4 100644
--- a/dash.el
+++ b/dash.el
@@ -335,6 +335,18 @@ Returns `nil` both if all items match the predicate, and
if none of the items ma
"Returns a list of ((-take-while PRED LIST) (-drop-while PRED LIST))"
(--split-with (funcall pred it) list))
+(defmacro --separate (form list)
+ "Anaphoric form of `-separate'."
+ (let ((y (make-symbol "yes"))
+ (n (make-symbol "no")))
+ `(let (,y ,n)
+ (--each ,list (if ,form (!cons it ,y) (!cons it ,n)))
+ (list (nreverse ,y) (nreverse ,n)))))
+
+(defun -separate (pred list)
+ "Returns a list of ((-filter PRED LIST) (-remove PRED LIST))."
+ (--separate (funcall pred it) list))
+
(defun -partition (n list)
"Returns a new list with the items in LIST grouped into N-sized sublists.
If there are not enough items to make the last group N-sized,
diff --git a/examples.el b/examples.el
index bb07fa0..8bc0a37 100644
--- a/examples.el
+++ b/examples.el
@@ -130,6 +130,11 @@
(-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 -separate
+ (-separate (lambda (num) (= 0 (% num 2))) '(1 2 3 4 5 6 7)) => '((2 4 6) (1
3 5 7))
+ (--separate (< it 5) '(3 7 5 9 3 2 1 4 6)) => '((3 3 2 1 4) (7 5 9 6))
+ (-separate 'cdr '((1 2) (1) (1 2 3) (4))) => '(((1 2) (1 2 3)) ((1) (4))))
+
(defexamples -partition
(-partition 2 '(1 2 3 4 5 6)) => '((1 2) (3 4) (5 6))
(-partition 2 '(1 2 3 4 5 6 7)) => '((1 2) (3 4) (5 6))
- [elpa] externals/dash 03370ea 108/439: Simplify examples-to-docs and examples-to-tests with dash, (continued)
- [elpa] externals/dash 03370ea 108/439: Simplify examples-to-docs and examples-to-tests with dash, Phillip Lord, 2015/08/04
- [elpa] externals/dash ba80875 109/439: Nice indentation for --each, --each-while and --dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9a3dfdd 113/439: Name parameter PRED when function expects predicate., Phillip Lord, 2015/08/04
- [elpa] externals/dash a081c72 114/439: Fix tests., Phillip Lord, 2015/08/04
- [elpa] externals/dash 9faa422 115/439: Add -partition-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash 51ddc13 110/439: Nice indentation for threading macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash 2c5b86e 117/439: Add -join as alias to -distinct., Phillip Lord, 2015/08/04
- [elpa] externals/dash e9de223 116/439: Rename -replace-where to -map-when, Phillip Lord, 2015/08/04
- [elpa] externals/dash cca9b1b 121/439: Also run tests on Emacs24, Phillip Lord, 2015/08/04
- [elpa] externals/dash d857f73 118/439: Merge pull request #3 from rejeep/join-alias, Phillip Lord, 2015/08/04
- [elpa] externals/dash c025efb 122/439: Add -separate (thanks @Fuco1),
Phillip Lord <=
- [elpa] externals/dash 69e054e 124/439: Switch around order of Contribute and Contributors parts in readme., Phillip Lord, 2015/08/04
- [elpa] externals/dash 8f91ec8 126/439: 1.0.2, Phillip Lord, 2015/08/04
- [elpa] externals/dash f034c16 119/439: Add -union (thanks to @Fuco1), Phillip Lord, 2015/08/04
- [elpa] externals/dash 5e72ff9 120/439: Include numbers in github ids., Phillip Lord, 2015/08/04
- [elpa] externals/dash a23aa4b 128/439: Add examples for -group-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash c669282 123/439: Add @Fuco1 to list of contributors., Phillip Lord, 2015/08/04
- [elpa] externals/dash 7f7ac33 130/439: Add Takafumi Arakaki to list of contributors., Phillip Lord, 2015/08/04
- [elpa] externals/dash 467dfa7 133/439: Add -map-indexed, Phillip Lord, 2015/08/04
- [elpa] externals/dash 85bd4e0 131/439: Add @tali713's -applify, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7e4ee06 135/439: 1.0.3, Phillip Lord, 2015/08/04