[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 4205e58 064/439: Add clojure threading macros, !-
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 4205e58 064/439: Add clojure threading macros, !-> and !->> |
Date: |
Tue, 04 Aug 2015 20:26:26 +0000 |
branch: externals/dash
commit 4205e58d7ea98096d2e7ca7e2a7ff750da66f514
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Add clojure threading macros, !-> and !->>
---
bang.el | 23 +++++++++++++++++++++++
examples.el | 13 +++++++++++++
2 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/bang.el b/bang.el
index b8879c1..81c2350 100644
--- a/bang.el
+++ b/bang.el
@@ -154,6 +154,29 @@ args first and then ARGS."
`(closure (t) (&rest args)
(apply ',fn (append args ',args))))
+(defmacro !-> (x &optional form &rest more)
+ "Threads the expr through the forms. Inserts X as the second
+item in the first form, making a list of it if it is not a list
+already. If there are more forms, inserts the first form as the
+second item in second form, etc."
+ (cond
+ ((null form) x)
+ ((null more) (if (listp form)
+ `(,(car form) ,x ,@(cdr form))
+ (list form x)))
+ (:else `(!-> (!-> ,x ,form) ,@more))))
+
+(defmacro !->> (x form &rest more)
+ "Threads the expr through the forms. Inserts X as the last item
+in the first form, making a list of it if it is not a list
+already. If there are more forms, inserts the first form as the
+last item in second form, etc."
+ (if (null more)
+ (if (listp form)
+ `(,(car form) ,@(cdr form) ,x)
+ (list form x))
+ `(!->> (!->> ,x ,form) ,@more)))
+
(defun !distinct (list)
"Return a new list with all duplicates removed.
The test for equality is done with `equal',
diff --git a/examples.el b/examples.el
index a57af86..2fcd990 100644
--- a/examples.el
+++ b/examples.el
@@ -71,6 +71,19 @@
(funcall (!rpartial '- 5) 8) => 3
(funcall (!rpartial '- 5 2) 10) => 3)
+(defexamples !->
+ (!-> "Abc") => "Abc"
+ (!-> "Abc" (concat "def")) => "Abcdef"
+ (!-> "Abc" (concat "def") (concat "ghi")) => "Abcdefghi"
+ (!-> 5 square) => 25
+ (!-> 5 (+ 3) square) => 64)
+
+(defexamples !->>
+ (!->> "Abc" (concat "def")) => "defAbc"
+ (!->> "Abc" (concat "def") (concat "ghi")) => "ghidefAbc"
+ (!->> 5 (- 8)) => 3
+ (!->> 5 (- 3) square) => 4)
+
(defexamples !difference
(!difference '() '()) => '()
(!difference '(1 2 3) '(4 5 6)) => '(1 2 3)
- [elpa] externals/dash db8a745 056/439: Add !each, (continued)
- [elpa] externals/dash db8a745 056/439: Add !each, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6be4c03 058/439: !first, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0991c29 057/439: Added some common aliases, Phillip Lord, 2015/08/04
- [elpa] externals/dash a6323eb 059/439: Add some tests that verify that the lists are evaled by the anaphoric macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash 70488c2 063/439: Add !rpartial, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1a7ad85 065/439: Mention Melpa in README, Phillip Lord, 2015/08/04
- [elpa] externals/dash d83ea8a 061/439: Add installation instructions., Phillip Lord, 2015/08/04
- [elpa] externals/dash 047eeea 066/439: Run tests on Emacs 24., Phillip Lord, 2015/08/04
- [elpa] externals/dash 5bd4593 067/439: Add note about !rpartial only working on Emacs 24+, Phillip Lord, 2015/08/04
- [elpa] externals/dash 05dec7a 062/439: Fix example., Phillip Lord, 2015/08/04
- [elpa] externals/dash 4205e58 064/439: Add clojure threading macros, !-> and !->>,
Phillip Lord <=
- [elpa] externals/dash 6520496 060/439: First release, remove warning., Phillip Lord, 2015/08/04
- [elpa] externals/dash ca3eea7 070/439: Fix examples-to-docs to support documenting macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash b29a5bb 071/439: Use make-symbol in macros to avoid names clashing., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6f17346 068/439: Don't run !rpartial tests on Emacsen <24, Phillip Lord, 2015/08/04
- [elpa] externals/dash 66ffaa6 072/439: Add !interpose, Phillip Lord, 2015/08/04
- [elpa] externals/dash ec6a85f 074/439: Add threading macro !!-> with `it` as placeholder., Phillip Lord, 2015/08/04
- [elpa] externals/dash 9410f7e 073/439: Add !replace-where, Phillip Lord, 2015/08/04
- [elpa] externals/dash cd2a793 069/439: Run travis-ci on both E23 and E24, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4e76865 075/439: Add !take-while, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6238f8f 077/439: Add !split-with, Phillip Lord, 2015/08/04