[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash f780322 305/439: Add `-flatten-n`
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash f780322 305/439: Add `-flatten-n` |
Date: |
Tue, 04 Aug 2015 20:29:28 +0000 |
branch: externals/dash
commit f780322bb6a546c2f13bcacb6ca21eb92b6e2fe5
Author: Matus Goljer <address@hidden>
Commit: Matus Goljer <address@hidden>
Add `-flatten-n`
---
README.md | 11 +++++++++++
dash.el | 4 ++++
dev/examples.el | 8 ++++++++
3 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index 092aa55..4b55241 100644
--- a/README.md
+++ b/README.md
@@ -44,6 +44,7 @@ Include this in your emacs settings to get syntax
highlighting:
* [-map-when](#-map-when-pred-rep-list) `(pred rep list)`
* [-map-indexed](#-map-indexed-fn-list) `(fn list)`
* [-flatten](#-flatten-l) `(l)`
+* [-flatten-n](#-flatten-n-num-list) `(num list)`
* [-concat](#-concat-rest-lists) `(&rest lists)`
* [-mapcat](#-mapcat-fn-list) `(fn list)`
* [-slice](#-slice-list-from-optional-to) `(list from &optional to)`
@@ -301,6 +302,16 @@ Takes a nested list `l` and returns its contents as a
single, flat list.
(-flatten '(1 2 (3 . 4))) ;; => '(1 2 (3 . 4))
```
+#### -flatten-n `(num list)`
+
+Flatten `num` levels of a nested `list`.
+
+```cl
+(-flatten-n 1 '((1 2) ((3 4) ((5 6))))) ;; => '(1 2 (3 4) ((5 6)))
+(-flatten-n 2 '((1 2) ((3 4) ((5 6))))) ;; => '(1 2 3 4 (5 6))
+(-flatten-n 3 '((1 2) ((3 4) ((5 6))))) ;; => '(1 2 3 4 5 6)
+```
+
#### -concat `(&rest lists)`
Returns a new list with the concatenation of the elements in the supplied
`lists`.
diff --git a/dash.el b/dash.el
index 2e2eccf..a411e60 100644
--- a/dash.el
+++ b/dash.el
@@ -275,6 +275,10 @@ through the REP function."
(-mapcat '-flatten l)
(list l)))
+(defun -flatten-n (num list)
+ "Flatten NUM levels of a nested LIST."
+ (-last-item (--iterate (--mapcat (-list it) it) list (1+ num))))
+
(defun -concat (&rest lists)
"Returns a new list with the concatenation of the elements in the supplied
LISTS."
(apply 'append lists))
diff --git a/dev/examples.el b/dev/examples.el
index 9520f44..ef9c3b8 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -48,6 +48,14 @@
(-flatten '((1 (2 3) (((4 (5))))))) => '(1 2 3 4 5)
(-flatten '(1 2 (3 . 4))) => '(1 2 (3 . 4)))
+ (defexamples -flatten-n
+ (-flatten-n 1 '((1 2) ((3 4) ((5 6))))) => '(1 2 (3 4) ((5 6)))
+ (-flatten-n 2 '((1 2) ((3 4) ((5 6))))) => '(1 2 3 4 (5 6))
+ (-flatten-n 3 '((1 2) ((3 4) ((5 6))))) => '(1 2 3 4 5 6)
+ (-flatten-n 0 '(3 4)) => '(3 4)
+ (-flatten-n 0 '((1 2) (3 4))) => '((1 2) (3 4))
+ (-flatten-n 0 '(((1 2) (3 4)))) => '(((1 2) (3 4))))
+
(defexamples -concat
(-concat '(1)) => '(1)
(-concat '(1) '(2)) => '(1 2)
- [elpa] externals/dash 5086d24 293/439: Merge pull request #60 from rejeep/cask, (continued)
- [elpa] externals/dash 5086d24 293/439: Merge pull request #60 from rejeep/cask, Phillip Lord, 2015/08/04
- [elpa] externals/dash 43dcd37 295/439: Only eval NUM in --dotimes once, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4e6a965 294/439: Still better debug declarations, Phillip Lord, 2015/08/04
- [elpa] externals/dash 703bb59 297/439: Convert -zip to support variable-length arguments, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4ecfea6 296/439: Merge pull request #79 from Fuco1/debug-forms, Phillip Lord, 2015/08/04
- [elpa] externals/dash c08fcba 299/439: Fixed documentation of `-last-item'., Phillip Lord, 2015/08/04
- [elpa] externals/dash c952a54 300/439: Merge pull request #90 from tmalsburg/last-item-doc, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2dfd748 298/439: Merge pull request #87 from steventlamb/topic/make_zip_n_ary, Phillip Lord, 2015/08/04
- [elpa] externals/dash bd85b7c 302/439: Make -zip support infinite (circular) lists, Phillip Lord, 2015/08/04
- [elpa] externals/dash f0dd4cc 301/439: Add -annotate, Phillip Lord, 2015/08/04
- [elpa] externals/dash f780322 305/439: Add `-flatten-n`,
Phillip Lord <=
- [elpa] externals/dash fb51f8f 304/439: Merge pull request #88 from steventlamb/topic/zip_cycle_pad, Phillip Lord, 2015/08/04
- [elpa] externals/dash 00549e4 307/439: Add missing fontification keywords, Phillip Lord, 2015/08/04
- [elpa] externals/dash cd137e0 310/439: `-slice` should not fill the returned list with nils if to > length, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6b64ea7 303/439: Add functions for flexibly zipping uneven lists, Phillip Lord, 2015/08/04
- [elpa] externals/dash 63ec298 308/439: Merge pull request #92 from Fuco1/outer-product, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7185db8 311/439: [Issue #83] Add `step` to `-slice`, Phillip Lord, 2015/08/04
- [elpa] externals/dash a3021eb 313/439: Merge pull request #93 from lunaryorn/patch-1, Phillip Lord, 2015/08/04
- [elpa] externals/dash 624c501 306/439: Add `-table` and `-table-flat`, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0384eee 312/439: Improve Travis CI configuration, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3132ae0 314/439: Alias -tail to nthcdr, Phillip Lord, 2015/08/04