[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash fea1aa3 086/426: Add -interleave
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash fea1aa3 086/426: Add -interleave |
Date: |
Tue, 04 Aug 2015 19:36:53 +0000 |
branch: externals/dash
commit fea1aa363aa9ccee217b0b0d8ef02ef729078c31
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Add -interleave
---
README.md | 11 +++++++++++
dash.el | 8 ++++++++
examples.el | 6 ++++++
3 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 6e55e09..bd343dd 100644
--- a/README.md
+++ b/README.md
@@ -28,6 +28,7 @@ Or you can just dump `dash.el` in your load path somewhere.
* [-split-at](#split-at-n-list) `(n list)`
* [-split-with](#split-with-fn-list) `(fn list)`
* [-interpose](#interpose-sep-list) `(sep list)`
+* [-interleave](#interleave-rest-lists) `(&rest lists)`
* [-replace-where](#replace-where-pred-rep-list) `(pred rep list)`
* [-first](#first-fn-list) `(fn list)`
* [-difference](#difference-list-list2) `(list list2)`
@@ -244,6 +245,16 @@ Returns a new list of all elements in `list` separated by
`sep`.
(-interpose "-" '("a" "b" "c")) ;; => '("a" "-" "b" "-" "c")
```
+### -interleave `(&rest lists)`
+
+Returns a new list of the first item in each list, then the second etc.
+
+```cl
+(-interleave '(1 2) '("a" "b")) ;; => '(1 "a" 2 "b")
+(-interleave '(1 2) '("a" "b") '("A" "B")) ;; => '(1 "a" "A" 2 "b" "B")
+(-interleave '(1 2 3) '("a" "b")) ;; => '(1 "a" 2 "b")
+```
+
### -replace-where `(pred rep list)`
Returns a new list where the elements in `list` that does not match the `pred`
function
diff --git a/dash.el b/dash.el
index 6e3d266..c5deb09 100644
--- a/dash.el
+++ b/dash.el
@@ -217,6 +217,14 @@ Thus function FN should return a collection."
(setq list (cdr list)))
(nreverse result)))
+(defun -interleave (&rest lists)
+ "Returns a new list of the first item in each list, then the second etc."
+ (let (result)
+ (while (--all? (not (null it)) lists)
+ (--each lists (setq result (cons (car it) result)))
+ (setq lists (-map 'cdr lists)))
+ (nreverse result)))
+
(defmacro --replace-where (pred rep list)
"Anaphoric form of `-replace-where'."
(let ((l (make-symbol "list"))
diff --git a/examples.el b/examples.el
index 438f82b..4f1acf2 100644
--- a/examples.el
+++ b/examples.el
@@ -94,6 +94,12 @@
(-interpose "-" '("a")) => '("a")
(-interpose "-" '("a" "b" "c")) => '("a" "-" "b" "-" "c"))
+(defexamples -interleave
+ (-interleave '(1 2) '("a" "b")) => '(1 "a" 2 "b")
+ (-interleave '(1 2) '("a" "b") '("A" "B")) => '(1 "a" "A" 2 "b" "B")
+ (-interleave '(1 2 3) '("a" "b")) => '(1 "a" 2 "b")
+ (-interleave '(1 2 3) '("a" "b" "c" "d")) => '(1 "a" 2 "b" 3 "c"))
+
(defexamples -replace-where
(-replace-where 'even? 'square '(1 2 3 4)) => '(1 4 3 16)
(--replace-where (> it 2) (* it it) '(1 2 3 4)) => '(1 2 9 16)
- [elpa] externals/dash 6238f8f 077/426: Add !split-with, (continued)
- [elpa] externals/dash 6238f8f 077/426: Add !split-with, Phillip Lord, 2015/08/04
- [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 <=
- [elpa] externals/dash 38cc9e7 088/426: Simplify -interleave with -none?, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9ff9fd0 085/426: Move functions that are not strictly list related last., Phillip Lord, 2015/08/04
- [elpa] externals/dash 0c55a4b 090/426: 1.0.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4b5e24b 087/426: Docs: move -any? -all? -none? and -each up., Phillip Lord, 2015/08/04
- [elpa] externals/dash f8d74ff 091/426: Docs: update example text to match example code., Phillip Lord, 2015/08/04
- [elpa] externals/dash eacb6f2 092/426: Docs: Better generation of github urls., Phillip Lord, 2015/08/04
- [elpa] externals/dash 8c75026 080/426: Add !drop, Phillip Lord, 2015/08/04
- [elpa] externals/dash a2941cd 097/426: Typo, Phillip Lord, 2015/08/04
- [elpa] externals/dash b9b6330 079/426: Add !take, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6931d8a 094/426: Remove Melpa from installation while waiting for it to be included., Phillip Lord, 2015/08/04