emacs-elpa-diffs
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]