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

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

[elpa] externals/dash a3b40f8 058/316: Make --> bind IT for use anywhere


From: ELPA Syncer
Subject: [elpa] externals/dash a3b40f8 058/316: Make --> bind IT for use anywhere in FORMS, and add -as->.
Date: Mon, 15 Feb 2021 15:57:25 -0500 (EST)

branch: externals/dash
commit a3b40f8f01d12c118037c9045e30ceaac7068cd9
Author: Zachary Kanfer <zkanfer@gmail.com>
Commit: Zachary Kanfer <zkanfer@gmail.com>

    Make --> bind IT for use anywhere in FORMS, and add -as->.
---
 dash.el         | 34 +++++++++++++++++++++++-----------
 dev/examples.el | 12 +++++++++++-
 2 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/dash.el b/dash.el
index 10b1f05..4a33706 100644
--- a/dash.el
+++ b/dash.el
@@ -1354,17 +1354,29 @@ last item in second form, etc."
                   (list form x)))
    (:else `(->> (->> ,x ,form) ,@more))))
 
-(defmacro --> (x form &rest more)
-  "Thread the expr through the forms. Insert X at the position
-signified by the token `it' in the first form. If there are more
-forms, insert the first form at the position signified by `it' in
-in second form, etc."
-  (declare (debug (form &rest [&or symbolp (sexp &rest [&or "it" form])])))
-  (if (null more)
-      (if (listp form)
-          (--map-when (eq it 'it) x form)
-        (list form x))
-    `(--> (--> ,x ,form) ,@more)))
+(defmacro --> (x &rest forms)
+  "Starting with the value of X, thread each expression through FORMS.
+
+Insert X at the position signified by the token `it' in the first
+form.  If there are more forms, insert the first form at the position
+signified by `it' in in second form, etc."
+  (declare (debug (form body)))
+  `(-as-> ,x it ,@forms))
+
+(defmacro -as-> (value variable &rest forms)
+  "Starting with VALUE, thread VARIABLE through FORMS.
+
+In the first form, bind VARIABLE to VALUE.  In the second form, bind
+VARIABLE to the result of the first form, and so forth."
+  (declare (debug (form symbolp body)))
+  (if (null forms)
+      `,value
+    `(let ((,variable ,value))
+       (-as-> ,(if (symbolp (car forms))
+                 (list (car forms) variable)
+               (car forms))
+            ,variable
+              ,@(cdr forms)))))
 
 (defmacro -some-> (x &optional form &rest more)
   "When expr is non-nil, thread it through the first form (via `->'),
diff --git a/dev/examples.el b/dev/examples.el
index 7487292..6e3a2ad 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -801,7 +801,17 @@ new list."
   (defexamples -->
     (--> "def" (concat "abc" it "ghi")) => "abcdefghi"
     (--> "def" (concat "abc" it "ghi") (upcase it)) => "ABCDEFGHI"
-    (--> "def" (concat "abc" it "ghi") upcase) => "ABCDEFGHI")
+    (--> "def" (concat "abc" it "ghi") upcase) => "ABCDEFGHI"
+    (--> "def" upcase) => "DEF"
+    (--> 3 (car (list it))) => 3)
+
+  (defexamples -as->
+    (-as-> 3 my-var (1+ my-var) (list my-var) (mapcar (lambda (ele) (* 2 ele)) 
my-var)) => '(8)
+    (-as-> 3 my-var 1+) => 4
+    (-as-> 3 my-var) => 3
+    (-as-> "def" string (concat "abc" string "ghi")) => "abcdefghi"
+    (-as-> "def" string (concat "abc" string "ghi") upcase) => "ABCDEFGHI"
+    (-as-> "def" string (concat "abc" string "ghi") (upcase string)) => 
"ABCDEFGHI")
 
   (defexamples -some->
     (-some-> '(2 3 5)) => '(2 3 5)



reply via email to

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