[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash ec9afcb 255/426: Merge pull request #54 from Fuco1
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash ec9afcb 255/426: Merge pull request #54 from Fuco1/index/modify |
Date: |
Tue, 04 Aug 2015 19:38:07 +0000 |
branch: externals/dash
commit ec9afcb0995744432b33e7b144e7376d454b82cf
Merge: 8052eb9 d8ccf85
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Merge pull request #54 from Fuco1/index/modify
Add remove/modify functions for index/indices)
---
README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++
dash.el | 37 +++++++++++++++++++++++++++++++++++++
dev/examples.el | 36 ++++++++++++++++++++++++++++++++++++
3 files changed, 119 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index d22b9e1..ca1fd78 100644
--- a/README.md
+++ b/README.md
@@ -72,6 +72,10 @@ Include this in your emacs settings to get syntax
highlighting:
* [-drop-while](#-drop-while-pred-list) `(pred list)`
* [-rotate](#-rotate-n-list) `(n list)`
* [-insert-at](#-insert-at-n-x-list) `(n x list)`
+* [-replace-at](#-replace-at-n-x-list) `(n x list)`
+* [-update-at](#-update-at-n-func-list) `(n func list)`
+* [-remove-at](#-remove-at-n-list) `(n list)`
+* [-remove-at-indices](#-remove-at-indices-indices-list) `(indices list)`
### Reductions
@@ -385,6 +389,48 @@ Returns a list with `x` inserted into `list` at position
`n`.
(-insert-at 12 'x '(a b c)) ;; => '(a b c x)
```
+#### -replace-at `(n x list)`
+
+Return a list with element at Nth position in `list` replaced with `x`.
+
+```cl
+(-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)
+```
+
+#### -update-at `(n func list)`
+
+Return a list with element at Nth position in `list` replaced with `(func (nth
n list))`.
+
+```cl
+(-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")
+```
+
+#### -remove-at `(n list)`
+
+Return a list with element at Nth position in `list` removed.
+
+```cl
+(-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-indices `(indices list)`
+
+Return a list whose elements are elements from `list` without
+elements selected as `(nth i list)` for all i
+from `indices`.
+
+```cl
+(-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")
+```
+
## Reductions
diff --git a/dash.el b/dash.el
index 5bb4323..6445195 100644
--- a/dash.el
+++ b/dash.el
@@ -477,6 +477,38 @@ The time complexity is O(n)."
(let ((split-list (-split-at n list)))
(nconc (car split-list) (cons x (cadr split-list)))))
+(defun -replace-at (n x list)
+ "Return a list with element at Nth position in LIST replaced with X."
+ (let ((split-list (-split-at n list)))
+ (nconc (car split-list) (cons x (cdr (cadr split-list))))))
+
+(defun -update-at (n func list)
+ "Return a list with element at Nth position in LIST replaced with `(func
(nth n list))`."
+ (let ((split-list (-split-at n list)))
+ (nconc (car split-list) (cons (funcall func (car (cadr split-list))) (cdr
(cadr split-list))))))
+
+(defmacro --update-at (n form list)
+ "Anaphoric version of `-update-at'."
+ `(-update-at ,n (lambda (it) ,form) ,list))
+
+(defun -remove-at (n list)
+ "Return a list with element at Nth position in LIST removed."
+ (-remove-at-indices (list n) list))
+
+(defun -remove-at-indices (indices list)
+ "Return a list whose elements are elements from LIST without
+elements selected as `(nth i list)` for all i
+from INDICES."
+ (let* ((indices (-sort '< indices))
+ (diffs (cons (car indices) (-map '1- (-zip-with '- (cdr indices)
indices))))
+ r)
+ (--each diffs
+ (let ((split (-split-at it list)))
+ (!cons (car split) r)
+ (setq list (cdr (cadr split)))))
+ (!cons list r)
+ (-flatten (nreverse r))))
+
(defmacro --split-with (pred list)
"Anaphoric form of `-split-with'."
(let ((l (make-symbol "list"))
@@ -1180,6 +1212,11 @@ structure such as plist or alist."
"-split-at"
"-rotate"
"-insert-at"
+ "-replace-at"
+ "-update-at"
+ "--update-at"
+ "-remove-at"
+ "-remove-at-indices"
"--split-with"
"-split-with"
"-partition"
diff --git a/dev/examples.el b/dev/examples.el
index c31f4bf..a222b23 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -90,6 +90,42 @@
(-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"))
+
+(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"))
+
(def-example-group "Reductions" nil
(defexamples -reduce-from
(-reduce-from '- 10 '(1 2 3)) => 4
- [elpa] externals/dash c788474 264/426: Fix bug with nested lists in `-remove-at-indices`, (continued)
- [elpa] externals/dash c788474 264/426: Fix bug with nested lists in `-remove-at-indices`, Phillip Lord, 2015/08/04
- [elpa] externals/dash 396d6ac 271/426: Declare macro before using it., Phillip Lord, 2015/08/04
- [elpa] externals/dash 386ec0a 273/426: Add -same-items? function., Phillip Lord, 2015/08/04
- [elpa] externals/dash e7bc8fe 250/426: Make dash-specific font lock optional, Phillip Lord, 2015/08/04
- [elpa] externals/dash a84a434 267/426: 2.4.1 in readme-template too, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4818368 272/426: Release 2.4.3, Phillip Lord, 2015/08/04
- [elpa] externals/dash b661f96 269/426: Merge pull request #62 from Fuco1/consfix, Phillip Lord, 2015/08/04
- [elpa] externals/dash 25be31a 270/426: Release 2.4.2, Phillip Lord, 2015/08/04
- [elpa] externals/dash f86d235 268/426: Fix -cons*, Phillip Lord, 2015/08/04
- [elpa] externals/dash 3eb91fe 280/426: Add `-find-last-index`, Phillip Lord, 2015/08/04
- [elpa] externals/dash ec9afcb 255/426: Merge pull request #54 from Fuco1/index/modify,
Phillip Lord <=
- [elpa] externals/dash 930b390 278/426: Add -list function., Phillip Lord, 2015/08/04
- [elpa] externals/dash adaeff7 274/426: Merge pull request #65 from rejeep/same-items-predicate, Phillip Lord, 2015/08/04
- [elpa] externals/dash e6cae0b 279/426: Merge pull request #68 from rejeep/list-function, Phillip Lord, 2015/08/04
- [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