emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dash 0574686 089/316: Make tails and inits return all p


From: ELPA Syncer
Subject: [elpa] externals/dash 0574686 089/316: Make tails and inits return all prefixes including the empty one.
Date: Mon, 15 Feb 2021 15:57:32 -0500 (EST)

branch: externals/dash
commit 057468608dd64b6fb66420fc46ec11ce1c4792df
Author: Matus Goljer <matus.goljer@gmail.com>
Commit: Matus Goljer <matus.goljer@gmail.com>

    Make tails and inits return all prefixes including the empty one.
    
    It is easy for the user to drop the first/last item with cdr or
    -butlast, so let's be consistent with how reductions work
---
 dash.el         |  9 +++------
 dev/examples.el | 12 ++++++------
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/dash.el b/dash.el
index 4136851..aa6e9f5 100644
--- a/dash.el
+++ b/dash.el
@@ -2108,15 +2108,12 @@ or with `-compare-fn' if that's non-nil."
                    list))))
 
 (defun -inits (list)
-  "Return all non-empty prefixes of LIST."
+  "Return all prefixes of LIST."
   (nreverse (-map 'reverse (-tails (nreverse list)))))
 
 (defun -tails (list)
-  "Return all non-empty suffixes of LIST"
-  (-reduce-r-from
-   (lambda (it acc)
-     (cons (cons it (car acc)) acc))
-   nil list))
+  "Return all suffixes of LIST"
+  (-reductions-r-from 'cons nil list))
 
 (defun -contains? (list element)
   "Return non-nil if LIST contains ELEMENT.
diff --git a/dev/examples.el b/dev/examples.el
index 8e7b5dd..3b63879 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -638,14 +638,14 @@ new list."
     (-permutations '(a b c)) => '((a b c) (a c b) (b a c) (b c a) (c a b) (c b 
a)))
 
   (defexamples -inits
-    (-inits '(1 2 3 4)) => '((1) (1 2) (1 2 3) (1 2 3 4))
-    (-inits nil) => nil
-    (-inits '(1)) => '((1)))
+    (-inits '(1 2 3 4)) => '(nil (1) (1 2) (1 2 3) (1 2 3 4))
+    (-inits nil) => '(nil)
+    (-inits '(1)) => '(nil (1)))
 
   (defexamples -tails
-    (-tails '(1 2 3 4)) => '((1 2 3 4) (2 3 4) (3 4) (4))
-    (-tails nil) => nil
-    (-tails '(1)) => '((1)))
+    (-tails '(1 2 3 4)) => '((1 2 3 4) (2 3 4) (3 4) (4) nil)
+    (-tails nil) => '(nil)
+    (-tails '(1)) => '((1) nil))
 
   (defexamples -distinct
     (-distinct '()) => '()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]