[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 70488c2 063/439: Add !rpartial
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 70488c2 063/439: Add !rpartial |
Date: |
Tue, 04 Aug 2015 20:26:25 +0000 |
branch: externals/dash
commit 70488c2d6d34bb17b091deb3adab3a894864efb7
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Add !rpartial
---
README.md | 19 ++++++++++++++++---
bang.el | 15 ++++++++++++---
examples.el | 6 +++++-
3 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
index 55b33d0..5885998 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,7 @@ Or you can just dump `bang.el` in your load path somewhere.
* [!mapcat](#mapcat-fn-list) `(fn list)`
* [!first](#first-fn-list) `(fn list)`
* [!partial](#partial-fn-rest-args) `(fn &rest args)`
+* [!rpartial](#rpartial-fn-rest-args) `(fn &rest args)`
* [!difference](#difference-list-list2) `(list list2)`
* [!intersection](#intersection-list-list2) `(list list2)`
* [!distinct](#distinct-list) `(list)`
@@ -172,14 +173,26 @@ To get the first item in the list no questions asked, use
`car`.
Takes a function `fn` and fewer than the normal arguments to `fn`,
and returns a fn that takes a variable number of additional `args`.
-When called, the returned function calls `fn` with `args` +
-additional args.
+When called, the returned function calls `fn` with `args` first and
+then additional args.
```cl
-(funcall (!partial '+ 5) 3) ;; => 8
+(funcall (!partial '- 5) 3) ;; => 2
(funcall (!partial '+ 5 2) 3) ;; => 10
```
+### !rpartial `(fn &rest args)`
+
+Takes a function `fn` and fewer than the normal arguments to `fn`,
+and returns a fn that takes a variable number of additional `args`.
+When called, the returned function calls `fn` with the additional
+args first and then `args`.
+
+```cl
+(funcall (!rpartial '- 5) 8) ;; => 3
+(funcall (!rpartial '- 5 2) 10) ;; => 3
+```
+
### !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 7ea865c..b8879c1 100644
--- a/bang.el
+++ b/bang.el
@@ -141,9 +141,18 @@ Thus function FN should return a collection."
(defun !partial (fn &rest args)
"Takes a function FN and fewer than the normal arguments to FN,
and returns a fn that takes a variable number of additional ARGS.
-When called, the returned function calls FN with ARGS +
-additional args."
- (apply 'apply-partially fn args))
+When called, the returned function calls FN with ARGS first and
+then additional args."
+ `(closure (t) (&rest args)
+ (apply ',fn ,@(mapcar (lambda (arg) `',arg) args) args)))
+
+(defun !rpartial (fn &rest args)
+ "Takes a function FN and fewer than the normal arguments to FN,
+and returns a fn that takes a variable number of additional ARGS.
+When called, the returned function calls FN with the additional
+args first and then ARGS."
+ `(closure (t) (&rest args)
+ (apply ',fn (append args ',args))))
(defun !distinct (list)
"Return a new list with all duplicates removed.
diff --git a/examples.el b/examples.el
index e0fcf9f..a57af86 100644
--- a/examples.el
+++ b/examples.el
@@ -64,9 +64,13 @@
(!!first (> it 2) '(1 2 3)) => 3)
(defexamples !partial
- (funcall (!partial '+ 5) 3) => 8
+ (funcall (!partial '- 5) 3) => 2
(funcall (!partial '+ 5 2) 3) => 10)
+(defexamples !rpartial
+ (funcall (!rpartial '- 5) 8) => 3
+ (funcall (!rpartial '- 5 2) 10) => 3)
+
(defexamples !difference
(!difference '() '()) => '()
(!difference '(1 2 3) '(4 5 6)) => '(1 2 3)
- [elpa] externals/dash 9312469 053/439: !keep, (continued)
- [elpa] externals/dash 9312469 053/439: !keep, Phillip Lord, 2015/08/04
- [elpa] externals/dash 286d1d8 050/439: Show quotes around strings in examples., Phillip Lord, 2015/08/04
- [elpa] externals/dash 24262a1 054/439: Add file-local font-lock for defexamples and =>, Phillip Lord, 2015/08/04
- [elpa] externals/dash f59b480 055/439: Add !some and !every?, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2b89641 049/439: Remove needless duplication., Phillip Lord, 2015/08/04
- [elpa] externals/dash b337ef9 052/439: Sync examples-to-docs.el with the one in s.el, Phillip Lord, 2015/08/04
- [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 <=
- [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, 2015/08/04
- [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