[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash f034c16 119/426: Add -union (thanks to @Fuco1)
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash f034c16 119/426: Add -union (thanks to @Fuco1) |
Date: |
Tue, 04 Aug 2015 19:37:06 +0000 |
branch: externals/dash
commit f034c160e91638241a346db0655c0ab390f60b51
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Add -union (thanks to @Fuco1)
Fixes #4
---
README.md | 13 +++++++++++++
dash.el | 11 ++++++++++-
examples.el | 5 +++++
3 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/README.md b/README.md
index 2bacc0a..cd75eca 100644
--- a/README.md
+++ b/README.md
@@ -41,6 +41,7 @@ Or you can just dump `dash.el` in your load path somewhere.
* [-interpose](#-interpose-sep-list) `(sep list)`
* [-interleave](#-interleave-rest-lists) `(&rest lists)`
* [-first](#-first-pred-list) `(pred list)`
+* [-union](#-union-list-list) `(list list2)`
* [-difference](#-difference-list-list) `(list list2)`
* [-intersection](#-intersection-list-list) `(list list2)`
* [-distinct](#-distinct-list) `(list)`
@@ -395,6 +396,18 @@ To get the first item in the list no questions asked, use
`car`.
(--first (> it 2) '(1 2 3)) ;; => 3
```
+### -union `(list list2)`
+
+Return a new list containing the elements of `list1` and elements of `list2`
that are not in `list1`.
+The test for equality is done with `equal`,
+or with `-compare-fn` if that's non-nil.
+
+```cl
+(-union '(1 2 3) '(3 4 5)) ;; => '(1 2 3 4 5)
+(-union '(1 2 3 4) '()) ;; => '(1 2 3 4)
+(-union '(1 1 2 2) '(3 2 1)) ;; => '(1 1 2 2 3)
+```
+
### -difference `(list list2)`
Return a new list with only the members of `list` that are not in `list2`.
diff --git a/dash.el b/dash.el
index e76a81e..7933f53 100644
--- a/dash.el
+++ b/dash.el
@@ -472,7 +472,16 @@ or with `-compare-fn' if that's non-nil.
Alias: `-uniq'"
(let (result)
- (--each list (when (not (-contains? result it)) (!cons it result)))
+ (--each list (unless (-contains? result it) (!cons it result)))
+ (nreverse result)))
+
+(defun -union (list list2)
+ "Return a new list containing the elements of LIST1 and elements of LIST2
that are not in LIST1.
+The test for equality is done with `equal',
+or with `-compare-fn' if that's non-nil."
+ (let (result)
+ (--each list (!cons it result))
+ (--each list2 (unless (-contains? result it) (!cons it result)))
(nreverse result)))
(defalias '-uniq '-distinct)
diff --git a/examples.el b/examples.el
index 2d1fe27..bb07fa0 100644
--- a/examples.el
+++ b/examples.el
@@ -161,6 +161,11 @@
(-first 'even? '(1 3 5)) => nil
(--first (> it 2) '(1 2 3)) => 3)
+(defexamples -union
+ (-union '(1 2 3) '(3 4 5)) => '(1 2 3 4 5)
+ (-union '(1 2 3 4) '()) => '(1 2 3 4)
+ (-union '(1 1 2 2) '(3 2 1)) => '(1 1 2 2 3))
+
(defexamples -difference
(-difference '() '()) => '()
(-difference '(1 2 3) '(4 5 6)) => '(1 2 3)
- [elpa] externals/dash ba80875 109/426: Nice indentation for --each, --each-while and --dotimes, (continued)
- [elpa] externals/dash ba80875 109/426: Nice indentation for --each, --each-while and --dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash f1c8453 083/426: Rename to dash., Phillip Lord, 2015/08/04
- [elpa] externals/dash 51ddc13 110/426: Nice indentation for threading macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash ba60707 103/426: Use --each-while to simplify implementations., Phillip Lord, 2015/08/04
- [elpa] externals/dash c56925a 111/426: Add font-lock for new functions and the `it` token., Phillip Lord, 2015/08/04
- [elpa] externals/dash a081c72 114/426: Fix tests., Phillip Lord, 2015/08/04
- [elpa] externals/dash a336d78 112/426: Add -only-some?, Phillip Lord, 2015/08/04
- [elpa] externals/dash 81a3247 104/426: Let -each and -each-while take multiple forms., Phillip Lord, 2015/08/04
- [elpa] externals/dash d857f73 118/426: Merge pull request #3 from rejeep/join-alias, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9faa422 115/426: Add -partition-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash f034c16 119/426: Add -union (thanks to @Fuco1),
Phillip Lord <=
- [elpa] externals/dash 9a3dfdd 113/426: Name parameter PRED when function expects predicate., Phillip Lord, 2015/08/04
- [elpa] externals/dash cca9b1b 121/426: Also run tests on Emacs24, Phillip Lord, 2015/08/04
- [elpa] externals/dash c669282 123/426: Add @Fuco1 to list of contributors., Phillip Lord, 2015/08/04
- [elpa] externals/dash 12ed9f6 100/426: Add destructive operations !cons og !cdr, Phillip Lord, 2015/08/04
- [elpa] externals/dash c025efb 122/426: Add -separate (thanks @Fuco1), Phillip Lord, 2015/08/04
- [elpa] externals/dash 2c5b86e 117/426: Add -join as alias to -distinct., Phillip Lord, 2015/08/04
- [elpa] externals/dash 1c4e5d7 125/426: Remove eval from --reduce, it is evil., Phillip Lord, 2015/08/04
- [elpa] externals/dash 8f91ec8 126/426: 1.0.2, Phillip Lord, 2015/08/04
- [elpa] externals/dash 1120417 127/426: Add -group-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5e72ff9 120/426: Include numbers in github ids., Phillip Lord, 2015/08/04