branch: externals/dash
commit 25c114c53ca650f978f62285aa78a3f4847a2e3c
Author: Wilfred Hughes <[email protected]>
Commit: Wilfred Hughes <[email protected]>
Implementing a shallow copy counterpart to -clone.
---
README.md | 10 ++++++++++
dash.el | 4 ++++
dev/examples.el | 8 ++++++--
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 435879e..8eb8e26 100644
--- a/README.md
+++ b/README.md
@@ -50,6 +50,7 @@ new list.
* [-splice](#-splice-pred-fun-list) `(pred fun list)`
* [-splice-list](#-splice-list-pred-new-list-list) `(pred new-list list)`
* [-mapcat](#-mapcat-fn-list) `(fn list)`
+* [-copy](#-copy-list) `(list)`
### Sublist selection
@@ -369,6 +370,15 @@ Thus function `fn` should return a list.
(--mapcat (list 0 it) '(1 2 3)) ;; => '(0 1 0 2 0 3)
```
+#### -copy `(list)`
+
+Create a shallow copy of `list`.
+
+```cl
+(-copy '(1 2 3)) ;; => '(1 2 3)
+(let ((a '(1 2 3))) (eq a (-copy a))) ;; => nil
+```
+
## Sublist selection
diff --git a/dash.el b/dash.el
index c8a1253..e83324d 100644
--- a/dash.el
+++ b/dash.el
@@ -311,6 +311,9 @@ See also: `-flatten'"
Thus function FN should return a list."
(--mapcat (funcall fn it) list))
+(defalias '-copy 'copy-sequence
+ "Create a shallow copy of LIST.")
+
(defun -splice (pred fun list)
"Splice lists generated by FUN in place of elements matching PRED in LIST.
@@ -1559,6 +1562,7 @@ structure such as plist or alist."
"-concat"
"-mapcat"
"--mapcat"
+ "-copy"
"-cons*"
"-snoc"
"-first"
diff --git a/dev/examples.el b/dev/examples.el
index 26ed0e4..d42b05c 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -48,7 +48,11 @@ new list."
(defexamples -mapcat
(-mapcat 'list '(1 2 3)) => '(1 2 3)
(-mapcat (lambda (item) (list 0 item)) '(1 2 3)) => '(0 1 0 2 0 3)
- (--mapcat (list 0 it) '(1 2 3)) => '(0 1 0 2 0 3)))
+ (--mapcat (list 0 it) '(1 2 3)) => '(0 1 0 2 0 3))
+
+ (defexamples -copy
+ (-copy '(1 2 3)) => '(1 2 3)
+ (let ((a '(1 2 3))) (eq a (-copy a))) => nil))
(def-example-group "Sublist selection"
"Functions returning a sublist of the original list."
@@ -620,7 +624,7 @@ new list."
"}"
'((elips-mode (foo (bar . booze)) (baz . qux)) (c-mode (foo .
bla) (bum . bam)))))
=> "{elips-mode : {foo : {bar -> booze}, baz -> qux}, c-mode : {foo ->
bla, bum -> bam}}")
-
+
(defexamples -clone
(let* ((a '(1 2 3)) (b (-clone a))) (nreverse a) b) => '(1 2 3)))