[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 0dab44c 084/439: Add -flatten
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 0dab44c 084/439: Add -flatten |
Date: |
Tue, 04 Aug 2015 20:26:41 +0000 |
branch: externals/dash
commit 0dab44c011bf8adec48da43c2155404b0ce73870
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Add -flatten
---
README.md | 10 ++++++++++
dash.el | 6 ++++++
examples.el | 4 ++++
3 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 55a1aff..58da129 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,7 @@ Or you can just dump `dash.el` in your load path somewhere.
* [-filter](#filter-fn-list) `(fn list)`
* [-remove](#remove-fn-list) `(fn list)`
* [-keep](#keep-fn-list) `(fn list)`
+* [-flatten](#flatten-l) `(l)`
* [-concat](#concat-rest-lists) `(&rest lists)`
* [-mapcat](#mapcat-fn-list) `(fn list)`
* [-take](#take-n-list) `(n list)`
@@ -146,6 +147,15 @@ Returns a new list of the non-nil results of applying `fn`
to the items in `list
(--keep (when (> it 3) (* 10 it)) '(1 2 3 4 5 6)) ;; => '(40 50 60)
```
+### -flatten `(l)`
+
+Takes a nested list `l` and returns its contents as a single, flat list.
+
+```cl
+(-flatten '((1))) ;; => '(1)
+(-flatten '((1 (2 3) (((4 (5))))))) ;; => '(1 2 3 4 5)
+```
+
### -concat `(&rest lists)`
Returns a new list with the concatenation of the elements in
diff --git a/dash.el b/dash.el
index 9781960..392019d 100644
--- a/dash.el
+++ b/dash.el
@@ -130,6 +130,12 @@ Alias: `-reject'"
"Returns a new list of the non-nil results of applying FN to the items in
LIST."
(--keep (funcall fn it) list))
+(defun -flatten (l)
+ "Takes a nested list L and returns its contents as a single, flat list."
+ (if (listp l)
+ (-mapcat '-flatten l)
+ (list l)))
+
(defun -concat (&rest lists)
"Returns a new list with the concatenation of the elements in
the supplied LISTS."
diff --git a/examples.el b/examples.el
index 6f11b60..fb03e5c 100644
--- a/examples.el
+++ b/examples.el
@@ -47,6 +47,10 @@
(-keep (lambda (num) (when (> num 3) (* 10 num))) '(1 2 3 4 5 6)) => '(40 50
60)
(--keep (when (> it 3) (* 10 it)) '(1 2 3 4 5 6)) => '(40 50 60))
+(defexamples -flatten
+ (-flatten '((1))) => '(1)
+ (-flatten '((1 (2 3) (((4 (5))))))) => '(1 2 3 4 5))
+
(defexamples -concat
(-concat '(1)) => '(1)
(-concat '(1) '(2)) => '(1 2)
- [elpa] externals/dash 9410f7e 073/439: Add !replace-where, (continued)
- [elpa] externals/dash 9410f7e 073/439: Add !replace-where, Phillip Lord, 2015/08/04
- [elpa] externals/dash cd2a793 069/439: Run travis-ci on both E23 and E24, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4e76865 075/439: Add !take-while, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6238f8f 077/439: Add !split-with, Phillip Lord, 2015/08/04
- [elpa] externals/dash b9b6330 079/439: Add !take, Phillip Lord, 2015/08/04
- [elpa] externals/dash 8c75026 080/439: Add !drop, Phillip Lord, 2015/08/04
- [elpa] externals/dash 123eaaa 078/439: Docs: Refer to !replace-where from !!replace-where., Phillip Lord, 2015/08/04
- [elpa] externals/dash ec835e4 081/439: Add !split-at, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3802890 082/439: Simplify !concat, Phillip Lord, 2015/08/04
- [elpa] externals/dash fea1aa3 086/439: Add -interleave, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0dab44c 084/439: Add -flatten,
Phillip Lord <=
- [elpa] externals/dash 82a12a2 076/439: Add !drop-while, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9ff9fd0 085/439: Move functions that are not strictly list related last., Phillip Lord, 2015/08/04
- [elpa] externals/dash 38cc9e7 088/439: Simplify -interleave with -none?, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4b5e24b 087/439: Docs: move -any? -all? -none? and -each up., Phillip Lord, 2015/08/04
- [elpa] externals/dash 0e5c69b 089/439: Docs: more concise example for anaphoric functions., Phillip Lord, 2015/08/04
- [elpa] externals/dash f8d74ff 091/439: Docs: update example text to match example code., Phillip Lord, 2015/08/04
- [elpa] externals/dash b0da7b2 093/439: Declare macros before using them., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6931d8a 094/439: Remove Melpa from installation while waiting for it to be included., Phillip Lord, 2015/08/04
- [elpa] externals/dash 0c55a4b 090/439: 1.0.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0bd26ac 096/439: Add aliases for -p instead of ?, Phillip Lord, 2015/08/04