diff --git a/dash.el b/dash.el index 9187c66..86f37c3 100644 --- a/dash.el +++ b/dash.el @@ -727,7 +727,9 @@ See also: `-flatten-n'" See also: `-flatten'" (declare (pure t) (side-effect-free t)) - (-last-item (--iterate (--mapcat (-list it) it) list (1+ num)))) + (dotimes (_ num) + (setq list (apply #'append (mapcar #'-list list)))) + list) (defun -concat (&rest lists) "Return a new list with the concatenation of the elements in the supplied LISTS." diff --git a/dev/examples.el b/dev/examples.el index a0b115f..6997d89 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -344,7 +344,10 @@ new list." (-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))) - (-flatten-n 1 '(((1 . 2)) ((3 . 4)))) => '((1 . 2) (3 . 4))) + (-flatten-n 1 '(((1 . 2)) ((3 . 4)))) => '((1 . 2) (3 . 4)) + (let ((l (list 1 (list 2) 3))) (-flatten-n 0 l) l) => '(1 (2) 3) + (let ((l (list 1 (list 2) 3))) (-flatten-n 1 l) l) => '(1 (2) 3) + (let ((l (list 1 (list 2) 3))) (-flatten-n 2 l) l) => '(1 (2) 3)) (defexamples -replace (-replace 1 "1" '(1 2 3 4 3 2 1)) => '("1" 2 3 4 3 2 "1")