branch: externals/dash commit 3075aea1a3de5a6d01e604cb4b7cb4fce5db400e Author: Matus Goljer <matus.gol...@gmail.com> Commit: Matus Goljer <matus.gol...@gmail.com>
Add -unzip --- README.md | 19 +++++++++++++++++++ dash.el | 13 +++++++++++++ dev/examples.el | 4 ++++ 3 files changed, 36 insertions(+) diff --git a/README.md b/README.md index e5a207c..f0d64a6 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,7 @@ Other list functions not fit to be classified elsewhere. * [-zip-with](#-zip-with-fn-list1-list2) `(fn list1 list2)` * [-zip](#-zip-rest-lists) `(&rest lists)` * [-zip-fill](#-zip-fill-fill-value-rest-lists) `(fill-value &rest lists)` +* [-unzip](#-unzip-lists) `(lists)` * [-cycle](#-cycle-list) `(list)` * [-pad](#-pad-fill-value-rest-lists) `(fill-value &rest lists)` * [-table](#-table-fn-rest-lists) `(fn &rest lists)` @@ -1536,6 +1537,24 @@ longest input list. (-zip-fill 0 '(1 2 3 4 5) '(6 7 8 9)) ;; => '((1 . 6) (2 . 7) (3 . 8) (4 . 9) (5 . 0)) ``` +#### -unzip `(lists)` + +Unzip `lists`. + +This works just like [`-zip`](#-zip-rest-lists) but takes a list of lists instead of +a variable number of arguments, such that + + (-unzip (-zip `l1` `l2` `l3` ...)) + +is identity (given that the lists are the same length). + +See also: [`-zip`](#-zip-rest-lists) + +```el +(-unzip (-zip '(1 2 3) '(a b c) '("e" "f" "g"))) ;; => '((1 2 3) (a b c) ("e" "f" "g")) +(-unzip '((1 2) (3 4) (5 6) (7 8) (9 10))) ;; => '((1 3 5 7 9) (2 4 6 8 10)) +``` + #### -cycle `(list)` Return an infinite copy of `list` that will cycle through the diff --git a/dash.el b/dash.el index d64a4e3..53849ee 100644 --- a/dash.el +++ b/dash.el @@ -1119,6 +1119,19 @@ longest input list." (declare (pure t) (side-effect-free t)) (apply '-zip (apply '-pad (cons fill-value lists)))) +(defun -unzip (lists) + "Unzip LISTS. + +This works just like `-zip' but takes a list of lists instead of +a variable number of arguments, such that + + (-unzip (-zip L1 L2 L3 ...)) + +is identity (given that the lists are the same length). + +See also: `-zip'" + (apply '-zip lists)) + (defun -cycle (list) "Return an infinite copy of LIST that will cycle through the elements and repeat from the beginning." diff --git a/dev/examples.el b/dev/examples.el index c846d08..52976cc 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -620,6 +620,10 @@ new list." (defexamples -zip-fill (-zip-fill 0 '(1 2 3 4 5) '(6 7 8 9)) => '((1 . 6) (2 . 7) (3 . 8) (4 . 9) (5 . 0))) + (defexamples -unzip + (-unzip (-zip '(1 2 3) '(a b c) '("e" "f" "g"))) => '((1 2 3) (a b c) ("e" "f" "g")) + (-unzip '((1 2) (3 4) (5 6) (7 8) (9 10))) => '((1 3 5 7 9) (2 4 6 8 10))) + (defexamples -cycle (-take 5 (-cycle '(1 2 3))) => '(1 2 3 1 2) (-take 7 (-cycle '(1 "and" 3))) => '(1 "and" 3 1 "and" 3 1)