[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash eea928a 320/426: Add -replace
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash eea928a 320/426: Add -replace |
Date: |
Tue, 04 Aug 2015 19:38:35 +0000 |
branch: externals/dash
commit eea928a05fa305c162f2952ccf292d3c0847b1f5
Author: Matus Goljer <address@hidden>
Commit: Matus Goljer <address@hidden>
Add -replace
---
README.md | 13 ++++++++
dash.el | 7 ++++
dev/examples.el | 91 +++++++++++++++++++++++++++++--------------------------
3 files changed, 68 insertions(+), 43 deletions(-)
diff --git a/README.md b/README.md
index e61d300..3ab0bd7 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,7 @@ Include this in your emacs settings to get syntax
highlighting:
* [-remove](#-remove-pred-list) `(pred list)`
* [-keep](#-keep-fn-list) `(fn list)`
* [-map-when](#-map-when-pred-rep-list) `(pred rep list)`
+* [-replace](#-replace-old-new-list) `(old new list)`
* [-map-indexed](#-map-indexed-fn-list) `(fn list)`
* [-flatten](#-flatten-l) `(l)`
* [-flatten-n](#-flatten-n-num-list) `(num list)`
@@ -285,6 +286,18 @@ through the `rep` function.
(--map-when (= it 2) 17 '(1 2 3 4)) ;; => '(1 17 3 4)
```
+#### -replace `(old new list)`
+
+Replace all `old` items in `list` with `new`.
+
+Elements are compared using `equal`.
+
+```cl
+(-replace 1 "1" '(1 2 3 4 3 2 1)) ;; => '("1" 2 3 4 3 2 "1")
+(-replace "foo" "bar" '("a" "nice" "foo" "sentence" "about" "foo")) ;; =>
'("a" "nice" "bar" "sentence" "about" "bar")
+(-replace 1 2 nil) ;; => nil
+```
+
#### -map-indexed `(fn list)`
Returns a new list consisting of the result of (`fn` index item) for each item
in `list`.
diff --git a/dash.el b/dash.el
index 0c7f873..0999736 100644
--- a/dash.el
+++ b/dash.el
@@ -271,6 +271,12 @@ through the REP function."
(defalias '--replace-where '--map-when)
(defalias '-replace-where '-map-when)
+(defun -replace (old new list)
+ "Replace all OLD items in LIST with NEW.
+
+Elements are compared using `equal'."
+ (--map-when (equal it old) new list))
+
(defun -flatten (l)
"Takes a nested list L and returns its contents as a single, flat list."
(if (and (listp l) (listp (cdr l)))
@@ -1464,6 +1470,7 @@ structure such as plist or alist."
"--map-when"
"-replace-where"
"--replace-where"
+ "-replace"
"-flatten"
"-flatten-n"
"-concat"
diff --git a/dev/examples.el b/dev/examples.el
index 9df65ba..b386d7c 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -39,6 +39,11 @@
(--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 -replace
+ (-replace 1 "1" '(1 2 3 4 3 2 1)) => '("1" 2 3 4 3 2 "1")
+ (-replace "foo" "bar" '("a" "nice" "foo" "sentence" "about" "foo")) =>
'("a" "nice" "bar" "sentence" "about" "bar")
+ (-replace 1 2 nil) => nil)
+
(defexamples -map-indexed
(-map-indexed (lambda (index item) (- item index)) '(1 2 3 4)) => '(1 1 1
1)
(--map-indexed (- it it-index) '(1 2 3 4)) => '(1 1 1 1))
@@ -108,49 +113,49 @@
(defexamples -insert-at
(-insert-at 1 'x '(a b c)) => '(a x b c)
- (-insert-at 12 'x '(a b c)) => '(a b c x)))
-
-(defexamples -replace-at
- (-replace-at 0 9 '(0 1 2 3 4 5)) => '(9 1 2 3 4 5)
- (-replace-at 1 9 '(0 1 2 3 4 5)) => '(0 9 2 3 4 5)
- (-replace-at 4 9 '(0 1 2 3 4 5)) => '(0 1 2 3 9 5)
- (-replace-at 5 9 '(0 1 2 3 4 5)) => '(0 1 2 3 4 9))
-
-(defexamples -update-at
- (-update-at 0 (lambda (x) (+ x 9)) '(0 1 2 3 4 5)) => '(9 1 2 3 4 5)
- (-update-at 1 (lambda (x) (+ x 8)) '(0 1 2 3 4 5)) => '(0 9 2 3 4 5)
- (--update-at 2 (length it) '("foo" "bar" "baz" "quux")) => '("foo" "bar" 3
"quux")
- (--update-at 2 (concat it "zab") '("foo" "bar" "baz" "quux")) => '("foo"
"bar" "bazzab" "quux"))
-
-(defexamples -remove-at
- (-remove-at 0 '("0" "1" "2" "3" "4" "5")) => '("1" "2" "3" "4" "5")
- (-remove-at 1 '("0" "1" "2" "3" "4" "5")) => '("0" "2" "3" "4" "5")
- (-remove-at 2 '("0" "1" "2" "3" "4" "5")) => '("0" "1" "3" "4" "5")
- (-remove-at 3 '("0" "1" "2" "3" "4" "5")) => '("0" "1" "2" "4" "5")
- (-remove-at 4 '("0" "1" "2" "3" "4" "5")) => '("0" "1" "2" "3" "5")
- (-remove-at 5 '("0" "1" "2" "3" "4" "5")) => '("0" "1" "2" "3" "4")
- (-remove-at 5 '((a b) (c d) (e f g) h i ((j) k) l (m))) => '((a b) (c d) (e
f g) h i l (m))
- (-remove-at 0 '(((a b) (c d) (e f g) h i ((j) k) l (m)))) => nil)
-
-(defexamples -remove-at-indices
- (-remove-at-indices '(0) '("0" "1" "2" "3" "4" "5")) => '("1" "2" "3" "4"
"5")
- (-remove-at-indices '(0 2 4) '("0" "1" "2" "3" "4" "5")) => '("1" "3" "5")
- (-remove-at-indices '(0 5) '("0" "1" "2" "3" "4" "5")) => '("1" "2" "3" "4")
- (-remove-at-indices '(1 2 3) '("0" "1" "2" "3" "4" "5")) => '("0" "4" "5")
- (-remove-at-indices '(0 1 2 3 4 5) '("0" "1" "2" "3" "4" "5")) => nil
- (-remove-at-indices '(2 0 4) '("0" "1" "2" "3" "4" "5")) => '("1" "3" "5")
- (-remove-at-indices '(5 0) '("0" "1" "2" "3" "4" "5")) => '("1" "2" "3" "4")
- (-remove-at-indices '(1 3 2) '("0" "1" "2" "3" "4" "5")) => '("0" "4" "5")
- (-remove-at-indices '(0 3 4 2 5 1) '("0" "1" "2" "3" "4" "5")) => nil
- (-remove-at-indices '(1) '("0" "1" "2" "3" "4" "5")) => '("0" "2" "3" "4"
"5")
- (-remove-at-indices '(2) '("0" "1" "2" "3" "4" "5")) => '("0" "1" "3" "4"
"5")
- (-remove-at-indices '(3) '("0" "1" "2" "3" "4" "5")) => '("0" "1" "2" "4"
"5")
- (-remove-at-indices '(4) '("0" "1" "2" "3" "4" "5")) => '("0" "1" "2" "3"
"5")
- (-remove-at-indices '(5) '("0" "1" "2" "3" "4" "5")) => '("0" "1" "2" "3"
"4")
- (-remove-at-indices '(1 2 4) '((a b) (c d) (e f g) h i ((j) k) l (m))) =>
'((a b) h ((j) k) l (m))
- (-remove-at-indices '(5) '((a b) (c d) (e f g) h i ((j) k) l (m))) => '((a
b) (c d) (e f g) h i l (m))
- (-remove-at-indices '(0) '(((a b) (c d) (e f g) h i ((j) k) l (m)))) => nil
- (-remove-at-indices '(2 3) '((0) (1) (2) (3) (4) (5) (6))) => '((0) (1) (4)
(5) (6)))
+ (-insert-at 12 'x '(a b c)) => '(a b c x))
+
+ (defexamples -replace-at
+ (-replace-at 0 9 '(0 1 2 3 4 5)) => '(9 1 2 3 4 5)
+ (-replace-at 1 9 '(0 1 2 3 4 5)) => '(0 9 2 3 4 5)
+ (-replace-at 4 9 '(0 1 2 3 4 5)) => '(0 1 2 3 9 5)
+ (-replace-at 5 9 '(0 1 2 3 4 5)) => '(0 1 2 3 4 9))
+
+ (defexamples -update-at
+ (-update-at 0 (lambda (x) (+ x 9)) '(0 1 2 3 4 5)) => '(9 1 2 3 4 5)
+ (-update-at 1 (lambda (x) (+ x 8)) '(0 1 2 3 4 5)) => '(0 9 2 3 4 5)
+ (--update-at 2 (length it) '("foo" "bar" "baz" "quux")) => '("foo" "bar" 3
"quux")
+ (--update-at 2 (concat it "zab") '("foo" "bar" "baz" "quux")) => '("foo"
"bar" "bazzab" "quux"))
+
+ (defexamples -remove-at
+ (-remove-at 0 '("0" "1" "2" "3" "4" "5")) => '("1" "2" "3" "4" "5")
+ (-remove-at 1 '("0" "1" "2" "3" "4" "5")) => '("0" "2" "3" "4" "5")
+ (-remove-at 2 '("0" "1" "2" "3" "4" "5")) => '("0" "1" "3" "4" "5")
+ (-remove-at 3 '("0" "1" "2" "3" "4" "5")) => '("0" "1" "2" "4" "5")
+ (-remove-at 4 '("0" "1" "2" "3" "4" "5")) => '("0" "1" "2" "3" "5")
+ (-remove-at 5 '("0" "1" "2" "3" "4" "5")) => '("0" "1" "2" "3" "4")
+ (-remove-at 5 '((a b) (c d) (e f g) h i ((j) k) l (m))) => '((a b) (c d)
(e f g) h i l (m))
+ (-remove-at 0 '(((a b) (c d) (e f g) h i ((j) k) l (m)))) => nil)
+
+ (defexamples -remove-at-indices
+ (-remove-at-indices '(0) '("0" "1" "2" "3" "4" "5")) => '("1" "2" "3" "4"
"5")
+ (-remove-at-indices '(0 2 4) '("0" "1" "2" "3" "4" "5")) => '("1" "3" "5")
+ (-remove-at-indices '(0 5) '("0" "1" "2" "3" "4" "5")) => '("1" "2" "3"
"4")
+ (-remove-at-indices '(1 2 3) '("0" "1" "2" "3" "4" "5")) => '("0" "4" "5")
+ (-remove-at-indices '(0 1 2 3 4 5) '("0" "1" "2" "3" "4" "5")) => nil
+ (-remove-at-indices '(2 0 4) '("0" "1" "2" "3" "4" "5")) => '("1" "3" "5")
+ (-remove-at-indices '(5 0) '("0" "1" "2" "3" "4" "5")) => '("1" "2" "3"
"4")
+ (-remove-at-indices '(1 3 2) '("0" "1" "2" "3" "4" "5")) => '("0" "4" "5")
+ (-remove-at-indices '(0 3 4 2 5 1) '("0" "1" "2" "3" "4" "5")) => nil
+ (-remove-at-indices '(1) '("0" "1" "2" "3" "4" "5")) => '("0" "2" "3" "4"
"5")
+ (-remove-at-indices '(2) '("0" "1" "2" "3" "4" "5")) => '("0" "1" "3" "4"
"5")
+ (-remove-at-indices '(3) '("0" "1" "2" "3" "4" "5")) => '("0" "1" "2" "4"
"5")
+ (-remove-at-indices '(4) '("0" "1" "2" "3" "4" "5")) => '("0" "1" "2" "3"
"5")
+ (-remove-at-indices '(5) '("0" "1" "2" "3" "4" "5")) => '("0" "1" "2" "3"
"4")
+ (-remove-at-indices '(1 2 4) '((a b) (c d) (e f g) h i ((j) k) l (m))) =>
'((a b) h ((j) k) l (m))
+ (-remove-at-indices '(5) '((a b) (c d) (e f g) h i ((j) k) l (m))) => '((a
b) (c d) (e f g) h i l (m))
+ (-remove-at-indices '(0) '(((a b) (c d) (e f g) h i ((j) k) l (m)))) => nil
+ (-remove-at-indices '(2 3) '((0) (1) (2) (3) (4) (5) (6))) => '((0) (1)
(4) (5) (6))))
(def-example-group "Reductions" nil
(defexamples -reduce-from
- [elpa] externals/dash f18a520 326/426: Release 2.7.0, (continued)
- [elpa] externals/dash f18a520 326/426: Release 2.7.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7eb8307 283/426: Merge pull request #71 from Fuco1/find-last-index, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7f0fadc 317/426: Add -prodfn, Phillip Lord, 2015/08/04
- [elpa] externals/dash 960b05f 276/426: Set -each, -each-while and -dotimes indent levels to 1., Phillip Lord, 2015/08/04
- [elpa] externals/dash d948086 315/426: Add -iteratefn, Phillip Lord, 2015/08/04
- [elpa] externals/dash a09a4b2 318/426: Add code markup for docstrings and fix erroneous whitespace in docstring, Phillip Lord, 2015/08/04
- [elpa] externals/dash 38307e3 223/426: Partition docs, Phillip Lord, 2015/08/04
- [elpa] externals/dash f3b0a55 321/426: Change -predicate-p examples to -predicate? to maintain consistency, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7e4adb5 319/426: Add missing keywords to highlight list, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2ecc073 316/426: Reorder the partition examples to follow more logical order, add tests, Phillip Lord, 2015/08/04
- [elpa] externals/dash eea928a 320/426: Add -replace,
Phillip Lord <=
- [elpa] externals/dash d9879e9 329/426: Release 2.8.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash f8873a0 327/426: Update readme-template with changes from last release, Phillip Lord, 2015/08/04
- [elpa] externals/dash 25c114c 330/426: Implementing a shallow copy counterpart to -clone., Phillip Lord, 2015/08/04
- [elpa] externals/dash f257fb9 328/426: Add -butlast, Phillip Lord, 2015/08/04
- [elpa] externals/dash 174747e 323/426: Add -splice and -splice-list, Phillip Lord, 2015/08/04
- [elpa] externals/dash ab99be6 335/426: Add -fix, Phillip Lord, 2015/08/04
- [elpa] externals/dash b1e585d 337/426: Update copyright notice, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3adad97 334/426: Add -non-nil, Phillip Lord, 2015/08/04
- [elpa] externals/dash 166bccd 333/426: Add -tree-map-nodes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 05fa92f 342/426: [-let] Transpose nreverse/flatten, Phillip Lord, 2015/08/04