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

[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)



reply via email to

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