[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash eea928a 320/439: Add -replace
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash eea928a 320/439: Add -replace |
Date: |
Tue, 04 Aug 2015 20:29:38 +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 63ec298 308/439: Merge pull request #92 from Fuco1/outer-product, (continued)
- [elpa] externals/dash 63ec298 308/439: Merge pull request #92 from Fuco1/outer-product, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7185db8 311/439: [Issue #83] Add `step` to `-slice`, Phillip Lord, 2015/08/04
- [elpa] externals/dash a3021eb 313/439: Merge pull request #93 from lunaryorn/patch-1, Phillip Lord, 2015/08/04
- [elpa] externals/dash 624c501 306/439: Add `-table` and `-table-flat`, Phillip Lord, 2015/08/04
- [elpa] externals/dash 0384eee 312/439: Improve Travis CI configuration, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3132ae0 314/439: Alias -tail to nthcdr, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2ecc073 316/439: Reorder the partition examples to follow more logical order, add tests, Phillip Lord, 2015/08/04
- [elpa] externals/dash bbc1d9c 309/439: `--each-while` should also expose `it-index`, Phillip Lord, 2015/08/04
- [elpa] externals/dash d948086 315/439: Add -iteratefn, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7f0fadc 317/439: Add -prodfn, Phillip Lord, 2015/08/04
- [elpa] externals/dash eea928a 320/439: Add -replace,
Phillip Lord <=
- [elpa] externals/dash f3b0a55 321/439: Change -predicate-p examples to -predicate? to maintain consistency, Phillip Lord, 2015/08/04
- [elpa] externals/dash a09a4b2 318/439: Add code markup for docstrings and fix erroneous whitespace in docstring, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7e4adb5 319/439: Add missing keywords to highlight list, Phillip Lord, 2015/08/04
- [elpa] externals/dash 174747e 323/439: Add -splice and -splice-list, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5637bd6 322/439: Add alias from -find to -first, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9ebcce6 325/439: Add some niceties to font-locking of examples, Phillip Lord, 2015/08/04
- [elpa] externals/dash f8873a0 327/439: Update readme-template with changes from last release, Phillip Lord, 2015/08/04
- [elpa] externals/dash f18a520 326/439: Release 2.7.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash f257fb9 328/439: Add -butlast, Phillip Lord, 2015/08/04
- [elpa] externals/dash d9879e9 329/439: Release 2.8.0, Phillip Lord, 2015/08/04