branch: externals/dash commit 0272e8b1261344070ec4fc84921b1fb086e4d8f9 Author: Matus Goljer <matus.gol...@gmail.com> Commit: Matus Goljer <matus.gol...@gmail.com>
[Fix #158] -map-last does not modify input list. --- dash.el | 2 +- dev/examples.el | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dash.el b/dash.el index 3f20e5c..f310563 100644 --- a/dash.el +++ b/dash.el @@ -361,7 +361,7 @@ See also: `-map-when', `-replace-first'" "Replace first item in LIST satisfying PRED with result of REP called on this item. See also: `-map-when', `-replace-last'" - (nreverse (-map-first pred rep (nreverse list)))) + (nreverse (-map-first pred rep (reverse list)))) (defmacro --map-last (pred rep list) "Anaphoric form of `-map-last'." diff --git a/dev/examples.el b/dev/examples.el index 6377e69..06bc58f 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -69,6 +69,9 @@ new list." (-map-last 'even? 'square '(1 2 3 4)) => '(1 2 3 16) (--map-last (> it 2) (* it it) '(1 2 3 4)) => '(1 2 3 16) (--map-last (= it 2) 17 '(1 2 3 2)) => '(1 2 3 17) + ;; the next two tests assert that the input list is not modified #158 + (let ((l '(1 2 3))) (list (--map-last (< it 2) (number-to-string it) l) l)) => '(("1" 2 3) (1 2 3)) + (let ((l '(1 2 3))) (list (--map-last (< it 3) (number-to-string it) l) l)) => '((1 "2" 3) (1 2 3)) (-map-last 'even? 'square '(1 3 5 7)) => '(1 3 5 7) (-map-last 'even? 'square '(2)) => '(4) (-map-last 'even? 'square nil) => nil)