[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash ec6a85f 074/426: Add threading macro !!-> with `it
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash ec6a85f 074/426: Add threading macro !!-> with `it` as placeholder. |
Date: |
Tue, 04 Aug 2015 19:36:48 +0000 |
branch: externals/dash
commit ec6a85fcb588dc095f02a433499d3c3fec0d7367
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Add threading macro !!-> with `it` as placeholder.
---
README.md | 16 +++++++++++++++-
bang.el | 11 +++++++++++
examples.el | 10 ++++++++--
3 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 8cbfadd..5441fd2 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,7 @@ Or you can just dump `bang.el` in your load path somewhere.
* [!rpartial](#rpartial-fn-rest-args) `(fn &rest args)`
* [!->](#x-optional-form-rest-more) `(x &optional form &rest more)`
* [!->>](#x-form-rest-more) `(x form &rest more)`
+* [!!->](#x-form-rest-more) `(x form &rest more)`
* [!difference](#difference-list-list2) `(list list2)`
* [!intersection](#intersection-list-list2) `(list list2)`
* [!distinct](#distinct-list) `(list)`
@@ -179,8 +180,8 @@ through the `rep` function.
```cl
(!replace-where 'even? 'square '(1 2 3 4)) ;; => '(1 4 3 16)
-(!replace-where (lambda (n) (= n 3)) (lambda (n) 0) '(1 2 3 4)) ;; => '(1 2 0
4)
(!!replace-where (> it 2) (* it it) '(1 2 3 4)) ;; => '(1 2 9 16)
+(!!replace-where (= it 2) 17 '(1 2 3 4)) ;; => '(1 17 3 4)
```
### !first `(fn list)`
@@ -247,6 +248,19 @@ last item in second form, etc.
(!->> 5 (- 8)) ;; => 3
```
+### !!-> `(x form &rest more)`
+
+Threads the expr through the forms. Inserts `x` at the position
+signified by the token `it` in the first form. If there are more
+forms, inserts the first form at the position signified by `it`
+in in second form, etc.
+
+```cl
+(!!-> "def" (concat "abc" it "ghi")) ;; => "abcdefghi"
+(!!-> "def" (concat "abc" it "ghi") (upcase it)) ;; => "ABCDEFGHI"
+(!!-> "def" (concat "abc" it "ghi") upcase) ;; => "ABCDEFGHI"
+```
+
### !difference `(list list2)`
Return a new list with only the members of `list` that are not in `list2`.
diff --git a/bang.el b/bang.el
index 065662d..4f5c404 100644
--- a/bang.el
+++ b/bang.el
@@ -215,6 +215,17 @@ last item in second form, etc."
(list form x))
`(!->> (!->> ,x ,form) ,@more)))
+(defmacro !!-> (x form &rest more)
+ "Threads the expr through the forms. Inserts X at the position
+signified by the token `it' in the first form. If there are more
+forms, inserts the first form at the position signified by `it'
+in in second form, etc."
+ (if (null more)
+ (if (listp form)
+ (!!replace-where (eq it 'it) x form)
+ (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 6bfec6f..d894a4d 100644
--- a/examples.el
+++ b/examples.el
@@ -65,8 +65,9 @@
(defexamples !replace-where
(!replace-where 'even? 'square '(1 2 3 4)) => '(1 4 3 16)
- (!replace-where (lambda (n) (= n 3)) (lambda (n) 0) '(1 2 3 4)) => '(1 2 0 4)
- (!!replace-where (> it 2) (* it it) '(1 2 3 4)) => '(1 2 9 16))
+ (!!replace-where (> it 2) (* it it) '(1 2 3 4)) => '(1 2 9 16)
+ (!!replace-where (= it 2) 17 '(1 2 3 4)) => '(1 17 3 4)
+ (!replace-where (lambda (n) (= n 3)) (lambda (n) 0) '(1 2 3 4)) => '(1 2 0
4))
(defexamples !first
(!first 'even? '(1 2 3)) => 2
@@ -95,6 +96,11 @@
(!->> 5 (- 8)) => 3
(!->> 5 (- 3) square) => 4)
+(defexamples !!->
+ (!!-> "def" (concat "abc" it "ghi")) => "abcdefghi"
+ (!!-> "def" (concat "abc" it "ghi") (upcase it)) => "ABCDEFGHI"
+ (!!-> "def" (concat "abc" it "ghi") upcase) => "ABCDEFGHI")
+
(defexamples !difference
(!difference '() '()) => '()
(!difference '(1 2 3) '(4 5 6)) => '(1 2 3)
- [elpa] externals/dash cd2a793 069/426: Run travis-ci on both E23 and E24, (continued)
- [elpa] externals/dash cd2a793 069/426: Run travis-ci on both E23 and E24, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1a7ad85 065/426: Mention Melpa in README, Phillip Lord, 2015/08/04
- [elpa] externals/dash 6be4c03 058/426: !first, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0991c29 057/426: Added some common aliases, Phillip Lord, 2015/08/04
- [elpa] externals/dash ca3eea7 070/426: Fix examples-to-docs to support documenting macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash a6323eb 059/426: Add some tests that verify that the lists are evaled by the anaphoric macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash b29a5bb 071/426: Use make-symbol in macros to avoid names clashing., Phillip Lord, 2015/08/04
- [elpa] externals/dash 6520496 060/426: First release, remove warning., Phillip Lord, 2015/08/04
- [elpa] externals/dash 8bd82c7 051/426: Show empty lists as '() instead of nil in docs., Phillip Lord, 2015/08/04
- [elpa] externals/dash 66ffaa6 072/426: Add !interpose, Phillip Lord, 2015/08/04
- [elpa] externals/dash ec6a85f 074/426: Add threading macro !!-> with `it` as placeholder.,
Phillip Lord <=
- [elpa] externals/dash 6238f8f 077/426: Add !split-with, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4e76865 075/426: Add !take-while, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3802890 082/426: Simplify !concat, Phillip Lord, 2015/08/04
- [elpa] externals/dash ec835e4 081/426: Add !split-at, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0dab44c 084/426: Add -flatten, Phillip Lord, 2015/08/04
- [elpa] externals/dash 047eeea 066/426: Run tests on Emacs 24., Phillip Lord, 2015/08/04
- [elpa] externals/dash 9410f7e 073/426: Add !replace-where, Phillip Lord, 2015/08/04
- [elpa] externals/dash 123eaaa 078/426: Docs: Refer to !replace-where from !!replace-where., Phillip Lord, 2015/08/04
- [elpa] externals/dash 70488c2 063/426: Add !rpartial, Phillip Lord, 2015/08/04
- [elpa] externals/dash 82a12a2 076/426: Add !drop-while, Phillip Lord, 2015/08/04