Merge pull request #65 from rejeep/same-items-predicate

Add -same-items? function.
master
Magnar Sveen 12 years ago
commit adaeff7b38
  1. 13
      README.md
  2. 14
      dash.el
  3. 9
      dev/examples.el

@ -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

@ -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"

@ -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

Loading…
Cancel
Save