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

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

[elpa] externals/dash 38d44ed 128/316: Implement --doto


From: ELPA Syncer
Subject: [elpa] externals/dash 38d44ed 128/316: Implement --doto
Date: Mon, 15 Feb 2021 15:57:41 -0500 (EST)

branch: externals/dash
commit 38d44ed77e634f54daf18dfca09b087764415d75
Author: Ivan Yonchovski <yyoncho@gmail.com>
Commit: Ivan Yonchovski <yyoncho@gmail.com>

    Implement --doto
    
    Please let me know if you want me regenerate the docs. When I ran
    ./create-docs.sh it generates a lot of changes not related to this PR.
---
 dash.el         | 8 ++++++++
 dev/examples.el | 7 ++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/dash.el b/dash.el
index 066bf7c..550e1b6 100644
--- a/dash.el
+++ b/dash.el
@@ -86,6 +86,14 @@ the target form."
                  forms)
        ,retval)))
 
+(defmacro --doto (eval-initial-value &rest forms)
+  "Anaphoric form of `-doto'.
+Note: `it' is not required in each form."
+  (declare (indent 1))
+  `(let ((it ,eval-initial-value))
+     ,@forms
+     it))
+
 (defun -each (list fn)
   "Call FN with every item in LIST. Return nil, used for side-effects only."
   (--each list (funcall fn it)))
diff --git a/dev/examples.el b/dev/examples.el
index 28e61d7..a250b34 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -1259,7 +1259,12 @@ new list."
 
   (defexamples -doto
     (-doto '(1 2 3) (!cdr) (!cdr)) => '(3)
-    (-doto '(1 . 2) (setcar 3) (setcdr 4)) => '(3 . 4)))
+    (-doto '(1 . 2) (setcar 3) (setcdr 4)) => '(3 . 4))
+
+  (defexamples --doto
+    (gethash "key"
+             (--doto (make-hash-table :test 'equal)
+               (puthash "key" "value" it))) => "value"))
 
 (def-example-group "Destructive operations" nil
   (defexamples !cons



reply via email to

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