emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dash adaeff7 274/439: Merge pull request #65 from rejee


From: Phillip Lord
Subject: [elpa] externals/dash adaeff7 274/439: Merge pull request #65 from rejeep/same-items-predicate
Date: Tue, 04 Aug 2015 20:28:58 +0000

branch: externals/dash
commit adaeff7b3879cc66930f8d7445c6dce4c836b733
Merge: 4818368 386ec0a
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>

    Merge pull request #65 from rejeep/same-items-predicate
    
    Add -same-items? function.
---
 README.md       |   13 +++++++++++++
 dash.el         |   14 ++++++++++++++
 dev/examples.el |    9 ++++++++-
 3 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/README.md b/README.md
index 83ca63e..fd3c632 100644
--- a/README.md
+++ b/README.md
@@ -79,6 +79,7 @@ Include this in your emacs settings to get syntax 
highlighting:
 * [-none?](#-none-pred-list) `(pred list)`
 * [-only-some?](#-only-some-pred-list) `(pred list)`
 * [-contains?](#-contains-list-element) `(list element)`
+* [-same-items?](#-same-items-list-list2) `(list list2)`
 
 ### Partitioning
 
@@ -620,6 +621,18 @@ or with `-compare-fn` if that's non-nil.
 (-contains? '(1 2 3) 4) ;; => nil
 ```
 
+#### -same-items? `(list list2)`
+
+Return true if `list` and `list2` has the same items.
+
+The order of the elements in the lists does not matter.
+
+```cl
+(-same-items? '(1 2 3) '(1 2 3)) ;; => t
+(-same-items? '(1 2 3) '(3 2 1)) ;; => t
+(-same-items? '(1 2 3) '(1 2 3 4)) ;; => nil
+```
+
 
 ## Partitioning
 
diff --git a/dash.el b/dash.el
index b999df5..ae73bf3 100644
--- a/dash.el
+++ b/dash.el
@@ -964,6 +964,18 @@ or with `-compare-fn' if that's non-nil."
 
 (defalias '-contains-p '-contains?)
 
+(defun -same-items? (list list2)
+  "Return true if LIST and LIST2 has the same items.
+
+The order of the elements in the lists does not matter."
+  (let ((length-a (length list))
+        (length-b (length list2)))
+    (and
+     (= length-a length-b)
+     (= length-a (length (-intersection list list2))))))
+
+(defalias '-same-items-p '-same-items?)
+
 (defun -sort (comparator list)
   "Sort LIST, stably, comparing elements using COMPARATOR.
 Returns the sorted list.  LIST is NOT modified by side effects.
@@ -1284,6 +1296,8 @@ structure such as plist or alist."
                              "-difference"
                              "-contains?"
                              "-contains-p"
+                             "-same-items?"
+                             "-same-items-p"
                              "-sort"
                              "--sort"
                              "-repeat"
diff --git a/dev/examples.el b/dev/examples.el
index 792883a..f1b85bb 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -226,7 +226,14 @@
     (-contains? '(1 2 3) 2) => t
     (-contains? '(1 2 3) 4) => nil
     (-contains? '() 1) => nil
-    (-contains? '() '()) => nil))
+    (-contains? '() '()) => nil)
+
+  (defexamples -same-items?
+    (-same-items? '(1 2 3) '(1 2 3)) => t
+    (-same-items? '(1 2 3) '(3 2 1)) => t
+    (-same-items? '(1 2 3) '(1 2 3 4)) => nil
+    (-same-items? '((a . 1) (b . 2)) '((a . 1) (b . 2))) => t
+    (-same-items? '(1 2 3) '(2 3 1)) => t))
 
 (def-example-group "Partitioning" nil
   (defexamples -split-at



reply via email to

[Prev in Thread] Current Thread [Next in Thread]