[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash a336d78 112/439: Add -only-some?
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash a336d78 112/439: Add -only-some? |
Date: |
Tue, 04 Aug 2015 20:26:59 +0000 |
branch: externals/dash
commit a336d78bcbd18ce6eab1de98a2659fc7330bddc3
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Add -only-some?
---
dash.el | 19 ++++++++++++++++++-
examples.el | 6 ++++++
2 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/dash.el b/dash.el
index f01f547..8159bb7 100644
--- a/dash.el
+++ b/dash.el
@@ -241,7 +241,7 @@ Alias: `-every?'"
(defalias '--every-p '--all?)
(defmacro --none? (form list)
- "Anaphoric form `-none?'."
+ "Anaphoric form of `-none?'."
`(--all? (not ,form) ,list))
(defun -none? (fn list)
@@ -251,6 +251,23 @@ Alias: `-every?'"
(defalias '-none-p '-none?)
(defalias '--none-p '--none?)
+(defmacro --only-some? (form list)
+ "Anaphoric form of `-only-some?'."
+ (let ((y (make-symbol "yes"))
+ (n (make-symbol "no")))
+ `(let (,y ,n)
+ (--each-while ,list (not (and ,y ,n))
+ (if ,form (setq ,y t) (setq ,n t)))
+ (---truthy? (and ,y ,n)))))
+
+(defun -only-some? (pred list)
+ "Returns `t` if there is a mix of items in LIST that matches and does not
match PRED.
+Returns `nil` both if all items match the predicate, and if none of the items
match the predicate."
+ (--only-some? (funcall pred it) list))
+
+(defalias '-only-some-p '-only-some?)
+(defalias '--only-some-p '--only-some?)
+
(defun -take (n list)
"Returns a new list of the first N items in LIST, or all items if there are
fewer than N."
(let (result)
diff --git a/examples.el b/examples.el
index e5eb0f5..9d4518b 100644
--- a/examples.el
+++ b/examples.el
@@ -77,6 +77,12 @@
(-none? 'even? '(1 3 5)) => t
(--none? (= 0 (% it 2)) '(1 2 3)) => nil)
+(defexamples -only-some?
+ (-only-some? 'even? '(1 2 3)) => t
+ (-only-some? 'even? '(1 3 5)) => nil
+ (-only-some? 'even? '(2 4 6)) => nil
+ (--only-some? (> it 2) '(1 2 3)) => t)
+
(defexamples -each
(let (s) (-each '(1 2 3) (lambda (item) (setq s (cons item s))))) => nil
(let (s) (-each '(1 2 3) (lambda (item) (setq s (cons item s)))) s) => '(3 2
1)
- [elpa] externals/dash 79b56cc 101/439: Use --each, !cons and !cdr to simplify implementations., (continued)
- [elpa] externals/dash 79b56cc 101/439: Use --each, !cons and !cdr to simplify implementations., Phillip Lord, 2015/08/04
- [elpa] externals/dash 81a3247 104/439: Let -each and -each-while take multiple forms., Phillip Lord, 2015/08/04
- [elpa] externals/dash ba60707 103/439: Use --each-while to simplify implementations., Phillip Lord, 2015/08/04
- [elpa] externals/dash eb50d17 106/439: Add Melpa back in., Phillip Lord, 2015/08/04
- [elpa] externals/dash 4fedd2e 099/439: Add -partition and -partition-all, Phillip Lord, 2015/08/04
- [elpa] externals/dash 38eed45 095/439: Add rainbow-dash, Phillip Lord, 2015/08/04
- [elpa] externals/dash 49512b9 107/439: Simplify -take and -drop with --dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash ed47814 105/439: Add -dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash a08fc14 102/439: Add -each-while, Phillip Lord, 2015/08/04
- [elpa] externals/dash c56925a 111/439: Add font-lock for new functions and the `it` token., Phillip Lord, 2015/08/04
- [elpa] externals/dash a336d78 112/439: Add -only-some?,
Phillip Lord <=
- [elpa] externals/dash 03370ea 108/439: Simplify examples-to-docs and examples-to-tests with dash, Phillip Lord, 2015/08/04
- [elpa] externals/dash ba80875 109/439: Nice indentation for --each, --each-while and --dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9a3dfdd 113/439: Name parameter PRED when function expects predicate., Phillip Lord, 2015/08/04
- [elpa] externals/dash a081c72 114/439: Fix tests., Phillip Lord, 2015/08/04
- [elpa] externals/dash 9faa422 115/439: Add -partition-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash 51ddc13 110/439: Nice indentation for threading macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash 2c5b86e 117/439: Add -join as alias to -distinct., Phillip Lord, 2015/08/04
- [elpa] externals/dash e9de223 116/439: Rename -replace-where to -map-when, Phillip Lord, 2015/08/04
- [elpa] externals/dash cca9b1b 121/439: Also run tests on Emacs24, Phillip Lord, 2015/08/04
- [elpa] externals/dash d857f73 118/439: Merge pull request #3 from rejeep/join-alias, Phillip Lord, 2015/08/04