Merge pull request #282 from yyoncho/anamorphic-doto

Implement --doto
master
Matus Goljer 7 years ago committed by GitHub
commit 26f065fd60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      dash.el
  2. 7
      dev/examples.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)))

@ -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

Loading…
Cancel
Save