[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash e9de223 116/426: Rename -replace-where to -map-whe
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash e9de223 116/426: Rename -replace-where to -map-when |
Date: |
Tue, 04 Aug 2015 19:37:05 +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 c025efb 122/426: Add -separate (thanks @Fuco1), (continued)
- [elpa] externals/dash c025efb 122/426: Add -separate (thanks @Fuco1), Phillip Lord, 2015/08/04
- [elpa] externals/dash 2c5b86e 117/426: Add -join as alias to -distinct., Phillip Lord, 2015/08/04
- [elpa] externals/dash 1c4e5d7 125/426: Remove eval from --reduce, it is evil., Phillip Lord, 2015/08/04
- [elpa] externals/dash 8f91ec8 126/426: 1.0.2, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1120417 127/426: Add -group-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5e72ff9 120/426: Include numbers in github ids., Phillip Lord, 2015/08/04
- [elpa] externals/dash a23aa4b 128/426: Add examples for -group-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7f7ac33 130/426: Add Takafumi Arakaki to list of contributors., Phillip Lord, 2015/08/04
- [elpa] externals/dash 3044e83 129/426: Merge pull request #8 from tkf/group-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash 85bd4e0 131/426: Add @tali713's -applify, Phillip Lord, 2015/08/04
- [elpa] externals/dash e9de223 116/426: Rename -replace-where to -map-when,
Phillip Lord <=
- [elpa] externals/dash 002e4cd 132/426: Add tali713 to list of contributors., Phillip Lord, 2015/08/04
- [elpa] externals/dash 7e4ee06 135/426: 1.0.3, Phillip Lord, 2015/08/04
- [elpa] externals/dash e4521af 136/426: Add -repeat, Phillip Lord, 2015/08/04
- [elpa] externals/dash 69e054e 124/426: Switch around order of Contribute and Contributors parts in readme., Phillip Lord, 2015/08/04
- [elpa] externals/dash 78390f6 139/426: Merge pull request #12 from vemv/master, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1284bc6 134/426: Move .el files out of root., Phillip Lord, 2015/08/04
- [elpa] externals/dash da8dc62 138/426: Preserve newline at new-keywords, Phillip Lord, 2015/08/04
- [elpa] externals/dash 467dfa7 133/426: Add -map-indexed, Phillip Lord, 2015/08/04
- [elpa] externals/dash a196ac1 137/426: Fix -repeat, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9c5fbc5 143/426: nil is the default binding in let forms, Phillip Lord, 2015/08/04