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

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

[elpa] externals/dash 50e9f46 144/426: -cons* for making improper lists.


From: Phillip Lord
Subject: [elpa] externals/dash 50e9f46 144/426: -cons* for making improper lists.
Date: Tue, 04 Aug 2015 19:37:17 +0000

branch: externals/dash
commit 50e9f46710c64c2b05f00f775c8a9b1a56b183c1
Author: Nic Ferier <address@hidden>
Commit: Nic Ferier <address@hidden>

    -cons* for making improper lists.
---
 dash.el         |   18 ++++++++++++++++++
 dev/examples.el |    5 +++++
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/dash.el b/dash.el
index 2eebff8..233ff9a 100644
--- a/dash.el
+++ b/dash.el
@@ -218,6 +218,24 @@ through the REP function."
 Thus function FN should return a collection."
   (--mapcat (funcall fn it) list))
 
+(defun -cons* (&rest args)
+  "Makes a new list from the elements of ARGS.
+
+The last 2 members of ARGS are used as the final cons of the
+result so if the final member of ARGS is not a list the result is
+a dotted list."
+  (let (res)
+    (--each
+     args
+      (cond
+        ((not res)
+         (setq res it))
+        ((consp res)
+         (setcdr res (cons (cdr res) it)))
+        (t
+         (setq res (cons res it)))))
+    res))
+
 (defmacro --first (form list)
   "Anaphoric form of `-first'."
   (let ((n (make-symbol "needle")))
diff --git a/dev/examples.el b/dev/examples.el
index e9686ac..e847e6f 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -72,6 +72,11 @@
   (-mapcat (lambda (item) (list 0 item)) '(1 2 3)) => '(0 1 0 2 0 3)
   (--mapcat (list 0 it) '(1 2 3)) => '(0 1 0 2 0 3))
 
+(defexamples -cons*
+  (-cons* 1 2) => '(1 . 2)
+  (-cons* 1 2 3) => '(1 2 . 3)
+  (-cons* 1) => 1)
+
 (defexamples -any?
   (-any? 'even? '(1 2 3)) => t
   (-any? 'even? '(1 3 5)) => nil



reply via email to

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