branch: externals/dash commit 1e22ef6a292e91909fcb070cb362d0b69f68eb2e Merge: 85e8f62 a6e1436 Author: Matus Goljer <dota.k...@gmail.com> Commit: GitHub <nore...@github.com>
Merge pull request #263 from basil-conto/blc/common-suffix Add -common-suffix --- dash.el | 5 +++++ dev/examples.el | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/dash.el b/dash.el index 8d1d9a6..08924e2 100644 --- a/dash.el +++ b/dash.el @@ -2310,6 +2310,10 @@ or with `-compare-fn' if that's non-nil." (--reduce (--take-while (and acc (equal (pop acc) it)) it) lists)) +(defun -common-suffix (&rest lists) + "Return the longest common suffix of LISTS." + (nreverse (apply #'-common-prefix (mapcar #'reverse lists)))) + (defun -contains? (list element) "Return non-nil if LIST contains ELEMENT. @@ -2904,6 +2908,7 @@ structure such as plist or alist." "-inits" "-tails" "-common-prefix" + "-common-suffix" "-contains?" "-contains-p" "-same-items?" diff --git a/dev/examples.el b/dev/examples.el index 05669e9..43c0ace 100644 --- a/dev/examples.el +++ b/dev/examples.el @@ -389,13 +389,28 @@ new list." (defexamples -common-prefix (-common-prefix '(1)) => '(1) - (-common-prefix '(1 2) () '(1 2)) => () + (-common-prefix '(1 2) '(3 4) '(1 2)) => () (-common-prefix '(1 2) '(1 2 3) '(1 2 3 4)) => '(1 2) + (-common-prefix () '(1 2) '(1 2)) => () + (-common-prefix '(1 2) '(1 2) ()) => () + (-common-prefix '(1) '(1)) => '(1) (-common-prefix '(())) => '(()) (-common-prefix () ()) => () (-common-prefix ()) => () (-common-prefix) => ()) + (defexamples -common-suffix + (-common-suffix '(1)) => '(1) + (-common-suffix '(1 2) '(3 4) '(1 2)) => () + (-common-suffix '(1 2 3 4) '(2 3 4) '(3 4)) => '(3 4) + (-common-suffix () '(1 2) '(1 2)) => () + (-common-suffix '(1 2) '(1 2) ()) => () + (-common-suffix '(1) '(1)) => '(1) + (-common-suffix '(())) => '(()) + (-common-suffix () ()) => () + (-common-suffix ()) => () + (-common-suffix) => ()) + (defexamples -min (-min '(0)) => 0 (-min '(3 2 1)) => 1