[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 1e14307 061/316: Merge pull request #221 from zck/
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dash 1e14307 061/316: Merge pull request #221 from zck/it-anywhere-in--> |
Date: |
Mon, 15 Feb 2021 15:57:26 -0500 (EST) |
branch: externals/dash
commit 1e14307e2d829d3e4d502991d572eb9a5d7f173f
Merge: 524e6fe 13f9ece
Author: Matus Goljer <dota.keys@gmail.com>
Commit: GitHub <noreply@github.com>
Merge pull request #221 from zck/it-anywhere-in-->
Make --> bind IT for use anywhere in FORMS, and add -as->.
---
dash.el | 34 +++++++++++++++++++++++-----------
dev/examples.el | 28 +++++++++++++++++++++++++++-
2 files changed, 50 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..09b8262 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -801,7 +801,33 @@ 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
+
+ (--> '(1 2 3 4) (--map (1+ it) it)) => '(2 3 4 5)
+ (--map (--> it (1+ it)) '(1 2 3 4)) => '(2 3 4 5)
+
+ (--filter (--> it (equal 0 (mod it 2))) '(1 2 3 4)) => '(2 4)
+ (--> '(1 2 3 4) (--filter (equal 0 (mod it 2)) it)) => '(2 4)
+
+ (--annotate (--> it (< 1 it)) '(0 1 2 3)) => '((nil . 0)
+ (nil . 1)
+ (t . 2)
+ (t . 3))
+
+ (--> '(0 1 2 3) (--annotate (< 1 it) it)) => '((nil . 0)
+ (nil . 1)
+ (t . 2)
+ (t . 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)
- [elpa] externals/dash 9dfb01a 050/316: Correct use of eval-after-load, (continued)
- [elpa] externals/dash 9dfb01a 050/316: Correct use of eval-after-load, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 75cde71 052/316: Ensure that -first-item is as fast as car, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 05dc0aa 062/316: Add copyright assignment statement to documentation, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 4de2189 027/316: [Feature #185] -cut <> in first slot is a function, ELPA Syncer, 2021/02/15
- [elpa] externals/dash b45b38a 039/316: Fix typo, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 07c61f5 046/316: [#200] Add tests for generalized variables, ELPA Syncer, 2021/02/15
- [elpa] externals/dash ff323e0 049/316: Fix setf on emacs23 (#205), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 958e3fb 051/316: Merge pull request #206 from Silex/master, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 98e819e 053/316: Merge pull request #210 from Wilfred/car_opcode_with_first_item, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 6a57833 054/316: Add -iota (#207), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 1e14307 061/316: Merge pull request #221 from zck/it-anywhere-in-->,
ELPA Syncer <=
- [elpa] externals/dash 0468a31 063/316: Merge pull request #223 from phillord/feature/doc-copyright, ELPA Syncer, 2021/02/15
- [elpa] externals/dash f69a9df 071/316: Replace -first with -some in -any?, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 1422b70 042/316: Update info, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 73a28ae 043/316: Fix function application in documentation, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 53e641c 044/316: [Fix #202] -table-flat works on input of dimension 1, ELPA Syncer, 2021/02/15
- [elpa] externals/dash f04df47 048/316: Fix the debug declaration for -->, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 81ef1ef 055/316: Replace string-to-int with string-to-number (#216), ELPA Syncer, 2021/02/15
- [elpa] externals/dash 13a4718 059/316: Add new partition-before, -after methods., ELPA Syncer, 2021/02/15
- [elpa] externals/dash ca2f767 064/316: Show (VAR VAL) in the function signature, ELPA Syncer, 2021/02/15
- [elpa] externals/dash 0297166 068/316: Docs: Clarify that we don't modify the original list, ELPA Syncer, 2021/02/15