[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash e9de223 116/439: Rename -replace-where to -map-whe
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash e9de223 116/439: Rename -replace-where to -map-when |
Date: |
Tue, 04 Aug 2015 20:27:02 +0000 |
branch: externals/dash
commit e9de223c5af35b1b1d82b65cad993ce43c9db541
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Rename -replace-where to -map-when
- doesn't actually replace anything
- added alias to keep backwards compatability
---
README.md | 26 +++++++++++++-------------
dash.el | 33 +++++++++++++++++++--------------
examples.el | 12 ++++++------
3 files changed, 38 insertions(+), 33 deletions(-)
diff --git a/README.md b/README.md
index 95cb741..b93499e 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,7 @@ Or you can just dump `dash.el` in your load path somewhere.
* [-filter](#-filter-pred-list) `(pred list)`
* [-remove](#-remove-pred-list) `(pred list)`
* [-keep](#-keep-fn-list) `(fn list)`
+* [-map-when](#-map-when-pred-rep-list) `(pred rep list)`
* [-flatten](#-flatten-l) `(l)`
* [-concat](#-concat-rest-lists) `(&rest lists)`
* [-mapcat](#-mapcat-fn-list) `(fn list)`
@@ -39,7 +40,6 @@ Or you can just dump `dash.el` in your load path somewhere.
* [-partition-by](#-partition-by-fn-list) `(fn list)`
* [-interpose](#-interpose-sep-list) `(sep list)`
* [-interleave](#-interleave-rest-lists) `(&rest lists)`
-* [-replace-where](#-replace-where-pred-rep-list) `(pred rep list)`
* [-first](#-first-pred-list) `(pred list)`
* [-difference](#-difference-list-list) `(list list2)`
* [-intersection](#-intersection-list-list) `(list list2)`
@@ -157,6 +157,18 @@ Returns a new list of the non-nil results of applying `fn`
to the items in `list
(--keep (when (> it 3) (* 10 it)) '(1 2 3 4 5 6)) ;; => '(40 50 60)
```
+### -map-when `(pred rep list)`
+
+Returns a new list where the elements in `list` that does not match the `pred`
function
+are unchanged, and where the elements in `list` that do match the `pred`
function are mapped
+through the `rep` function.
+
+```cl
+(-map-when 'even? 'square '(1 2 3 4)) ;; => '(1 4 3 16)
+(--map-when (> it 2) (* it it) '(1 2 3 4)) ;; => '(1 2 9 16)
+(--map-when (= it 2) 17 '(1 2 3 4)) ;; => '(1 17 3 4)
+```
+
### -flatten `(l)`
Takes a nested list `l` and returns its contents as a single, flat list.
@@ -371,18 +383,6 @@ Returns a new list of the first item in each list, then
the second etc.
(-interleave '(1 2 3) '("a" "b")) ;; => '(1 "a" 2 "b")
```
-### -replace-where `(pred rep list)`
-
-Returns a new list where the elements in `list` that does not match the `pred`
function
-are unchanged, and where the elements in `list` that do match the `pred`
function are mapped
-through the `rep` function.
-
-```cl
-(-replace-where 'even? 'square '(1 2 3 4)) ;; => '(1 4 3 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)
-```
-
### -first `(pred list)`
Returns the first x in `list` where (`pred` x) is non-nil, else nil.
diff --git a/dash.el b/dash.el
index ebd6681..4ed2a8d 100644
--- a/dash.el
+++ b/dash.el
@@ -165,6 +165,22 @@ Alias: `-reject'"
"Returns a new list of the non-nil results of applying FN to the items in
LIST."
(--keep (funcall fn it) list))
+(defmacro --map-when (pred rep list)
+ "Anaphoric form of `-map-when'."
+ (let ((r (make-symbol "result")))
+ `(let (,r)
+ (--each ,list (!cons (if ,pred ,rep it) ,r))
+ (nreverse ,r))))
+
+(defun -map-when (pred rep list)
+ "Returns a new list where the elements in LIST that does not match the PRED
function
+are unchanged, and where the elements in LIST that do match the PRED function
are mapped
+through the REP function."
+ (--map-when (funcall pred it) (funcall rep it) list))
+
+(defalias '--replace-where '--map-when)
+(defalias '-replace-where '-map-when)
+
(defun -flatten (l)
"Takes a nested list L and returns its contents as a single, flat list."
(if (listp l)
@@ -394,19 +410,6 @@ The last group may contain less than N items."
(setq lists (-map 'cdr lists)))
(nreverse result)))
-(defmacro --replace-where (pred rep list)
- "Anaphoric form of `-replace-where'."
- (let ((r (make-symbol "result")))
- `(let (,r)
- (--each ,list (!cons (if ,pred ,rep it) ,r))
- (nreverse ,r))))
-
-(defun -replace-where (pred rep list)
- "Returns a new list where the elements in LIST that does not match the PRED
function
-are unchanged, and where the elements in LIST that do match the PRED function
are mapped
-through the REP function."
- (--replace-where (funcall pred it) (funcall rep it) list))
-
(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.
@@ -454,7 +457,7 @@ 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)
+ (--map-when (eq it 'it) x form)
(list form x))
`(--> (--> ,x ,form) ,@more)))
@@ -574,6 +577,8 @@ or with `-compare-fn' if that's non-nil."
"-partition-all"
"-interpose"
"-interleave"
+ "--map-when"
+ "-map-when"
"--replace-where"
"-replace-where"
"-partial"
diff --git a/examples.el b/examples.el
index 8b444bc..2d1fe27 100644
--- a/examples.el
+++ b/examples.el
@@ -47,6 +47,12 @@
(-keep (lambda (num) (when (> num 3) (* 10 num))) '(1 2 3 4 5 6)) => '(40 50
60)
(--keep (when (> it 3) (* 10 it)) '(1 2 3 4 5 6)) => '(40 50 60))
+(defexamples -map-when
+ (-map-when 'even? 'square '(1 2 3 4)) => '(1 4 3 16)
+ (--map-when (> it 2) (* it it) '(1 2 3 4)) => '(1 2 9 16)
+ (--map-when (= it 2) 17 '(1 2 3 4)) => '(1 17 3 4)
+ (-map-when (lambda (n) (= n 3)) (lambda (n) 0) '(1 2 3 4)) => '(1 2 0 4))
+
(defexamples -flatten
(-flatten '((1))) => '(1)
(-flatten '((1 (2 3) (((4 (5))))))) => '(1 2 3 4 5))
@@ -150,12 +156,6 @@
(-interleave '(1 2 3) '("a" "b")) => '(1 "a" 2 "b")
(-interleave '(1 2 3) '("a" "b" "c" "d")) => '(1 "a" 2 "b" 3 "c"))
-(defexamples -replace-where
- (-replace-where 'even? 'square '(1 2 3 4)) => '(1 4 3 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
(-first 'even? '(1 3 5)) => nil
- [elpa] externals/dash a08fc14 102/439: Add -each-while, (continued)
- [elpa] externals/dash a08fc14 102/439: Add -each-while, Phillip Lord, 2015/08/04
- [elpa] externals/dash c56925a 111/439: Add font-lock for new functions and the `it` token., Phillip Lord, 2015/08/04
- [elpa] externals/dash a336d78 112/439: Add -only-some?, Phillip Lord, 2015/08/04
- [elpa] externals/dash 03370ea 108/439: Simplify examples-to-docs and examples-to-tests with dash, Phillip Lord, 2015/08/04
- [elpa] externals/dash ba80875 109/439: Nice indentation for --each, --each-while and --dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9a3dfdd 113/439: Name parameter PRED when function expects predicate., Phillip Lord, 2015/08/04
- [elpa] externals/dash a081c72 114/439: Fix tests., Phillip Lord, 2015/08/04
- [elpa] externals/dash 9faa422 115/439: Add -partition-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash 51ddc13 110/439: Nice indentation for threading macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash 2c5b86e 117/439: Add -join as alias to -distinct., Phillip Lord, 2015/08/04
- [elpa] externals/dash e9de223 116/439: Rename -replace-where to -map-when,
Phillip Lord <=
- [elpa] externals/dash cca9b1b 121/439: Also run tests on Emacs24, Phillip Lord, 2015/08/04
- [elpa] externals/dash d857f73 118/439: Merge pull request #3 from rejeep/join-alias, Phillip Lord, 2015/08/04
- [elpa] externals/dash c025efb 122/439: Add -separate (thanks @Fuco1), Phillip Lord, 2015/08/04
- [elpa] externals/dash 69e054e 124/439: Switch around order of Contribute and Contributors parts in readme., Phillip Lord, 2015/08/04
- [elpa] externals/dash 8f91ec8 126/439: 1.0.2, Phillip Lord, 2015/08/04
- [elpa] externals/dash f034c16 119/439: Add -union (thanks to @Fuco1), Phillip Lord, 2015/08/04
- [elpa] externals/dash 5e72ff9 120/439: Include numbers in github ids., Phillip Lord, 2015/08/04
- [elpa] externals/dash a23aa4b 128/439: Add examples for -group-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash c669282 123/439: Add @Fuco1 to list of contributors., Phillip Lord, 2015/08/04
- [elpa] externals/dash 7f7ac33 130/439: Add Takafumi Arakaki to list of contributors., Phillip Lord, 2015/08/04