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

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

[elpa] externals/dash 4b5e24b 087/439: Docs: move -any? -all? -none? and


From: Phillip Lord
Subject: [elpa] externals/dash 4b5e24b 087/439: Docs: move -any? -all? -none? and -each up.
Date: Tue, 04 Aug 2015 20:26:43 +0000

branch: externals/dash
commit 4b5e24ba539e3594ef2e349363c85969c8d5fd22
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>

    Docs: move -any? -all? -none? and -each up.
---
 README.md   |   85 ++++++++++++++++++++++++++--------------------
 dash.el     |  108 +++++++++++++++++++++++++++++++---------------------------
 examples.el |   37 +++++++++++---------
 3 files changed, 127 insertions(+), 103 deletions(-)

diff --git a/README.md b/README.md
index bd343dd..0218e37 100644
--- a/README.md
+++ b/README.md
@@ -21,6 +21,10 @@ Or you can just dump `dash.el` in your load path somewhere.
 * [-flatten](#flatten-l) `(l)`
 * [-concat](#concat-rest-lists) `(&rest lists)`
 * [-mapcat](#mapcat-fn-list) `(fn list)`
+* [-any?](#any-fn-list) `(fn list)`
+* [-all?](#all-fn-list) `(fn list)`
+* [-none?](#none-fn-list) `(fn list)`
+* [-each](#each-list-fn) `(list fn)`
 * [-take](#take-n-list) `(n list)`
 * [-drop](#drop-n-list) `(n list)`
 * [-take-while](#take-while-fn-list) `(fn list)`
@@ -35,9 +39,6 @@ Or you can just dump `dash.el` in your load path somewhere.
 * [-intersection](#intersection-list-list2) `(list list2)`
 * [-distinct](#distinct-list) `(list)`
 * [-contains?](#contains-list-element) `(list element)`
-* [-any?](#any-fn-list) `(fn list)`
-* [-all?](#all-fn-list) `(fn list)`
-* [-each](#each-list-fn) `(list fn)`
 * [-partial](#partial-fn-rest-args) `(fn &rest args)`
 * [-rpartial](#rpartial-fn-rest-args) `(fn &rest args)`
 * [->](#x-optional-form-rest-more) `(x &optional form &rest more)`
@@ -178,6 +179,50 @@ Thus function `fn` should return a collection.
 (--mapcat (list 0 it) '(1 2 3)) ;; => '(0 1 0 2 0 3)
 ```
 
+### -any? `(fn list)`
+
+Returns t if (`fn` x) is non-nil for any x in `list`, else nil.
+
+Alias: `-some?`
+
+```cl
+(-any? 'even? '(1 2 3)) ;; => t
+(-any? 'even? '(1 3 5)) ;; => nil
+(--any? (= 0 (% it 2)) '(1 2 3)) ;; => t
+```
+
+### -all? `(fn list)`
+
+Returns t if (`fn` x) is non-nil for all x in `list`, else nil.
+
+Alias: `-every?`
+
+```cl
+(-all? 'even? '(1 2 3)) ;; => nil
+(-all? 'even? '(2 4 6)) ;; => t
+(--all? (= 0 (% it 2)) '(2 4 6)) ;; => t
+```
+
+### -none? `(fn list)`
+
+Returns t if (`fn` x) is nil for all x in `list`, else nil.
+
+```cl
+(-none? 'even? '(1 2 3)) ;; => nil
+(-none? 'even? '(1 3 5)) ;; => t
+(--none? (= 0 (% it 2)) '(1 2 3)) ;; => nil
+```
+
+### -each `(list fn)`
+
+Calls `fn` with every item in `list`. Returns nil, used for side-effects only.
+
+```cl
+(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)
+(let (s) (--each '(1 2 3) (setq s (cons it s))) s) ;; => '(3 2 1)
+```
+
 ### -take `(n list)`
 
 Returns a new list of the first `n` items in `list`, or all items if there are 
fewer than `n`.
@@ -326,40 +371,6 @@ or with `-compare-fn` if that's non-nil.
 (-contains? '(1 2 3) 4) ;; => nil
 ```
 
-### -any? `(fn list)`
-
-Returns t if (`fn` x) is non-nil for any x in `list`, else nil.
-
-Alias: `-some?`
-
-```cl
-(-any? 'even? '(1 2 3)) ;; => t
-(-any? 'even? '(1 3 5)) ;; => nil
-(--any? (= 0 (% it 2)) '(1 2 3)) ;; => t
-```
-
-### -all? `(fn list)`
-
-Returns t if (`fn` x) is non-nil for all x in `list`, else nil.
-
-Alias: `-every?`
-
-```cl
-(-all? 'even? '(1 2 3)) ;; => nil
-(-all? 'even? '(2 4 6)) ;; => t
-(--all? (= 0 (% it 2)) '(2 4 6)) ;; => t
-```
-
-### -each `(list fn)`
-
-Calls `fn` with every item in `list`. Returns nil, used for side-effects only.
-
-```cl
-(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)
-(let (s) (--each '(1 2 3) (setq s (cons it s))) s) ;; => '(3 2 1)
-```
-
 ### -partial `(fn &rest args)`
 
 Takes a function `fn` and fewer than the normal arguments to `fn`,
diff --git a/dash.el b/dash.el
index c5deb09..1d6a8ef 100644
--- a/dash.el
+++ b/dash.el
@@ -149,6 +149,64 @@ Alias: `-reject'"
 Thus function FN should return a collection."
   (--mapcat (funcall fn it) list))
 
+(defun ---truthy? (val)
+  (not (null val)))
+
+(defmacro --any? (form list)
+  "Anaphoric form of `-any?'."
+  `(---truthy? (--first ,form ,list)))
+
+(defun -any? (fn list)
+  "Returns t if (FN x) is non-nil for any x in LIST, else nil.
+
+Alias: `-some?'"
+  (--any? (funcall fn it) list))
+
+(defalias '-some? '-any?)
+(defalias '--some? '--any?)
+
+(defmacro --all? (form list)
+  "Anaphoric form of `-all?'."
+  (let ((l (make-symbol "list"))
+        (a (make-symbol "all")))
+    `(let ((,l ,list)
+           (,a t))
+       (while (and ,a ,l)
+         (let ((it (car ,l)))
+           (setq ,a ,form))
+         (setq ,l (cdr ,l)))
+       (---truthy? ,a))))
+
+(defun -all? (fn list)
+  "Returns t if (FN x) is non-nil for all x in LIST, else nil.
+
+Alias: `-every?'"
+  (--all? (funcall fn it) list))
+
+(defalias '-every? '-all?)
+(defalias '--every? '--all?)
+
+(defmacro --none? (form list)
+  "Anaphoric form `-none?'."
+  `(--all? (not ,form) ,list))
+
+(defun -none? (fn list)
+  "Returns t if (FN x) is nil for all x in LIST, else nil."
+  (--none? (funcall fn it) list))
+
+(defmacro --each (list form)
+  "Anaphoric form of `-each'."
+  (let ((l (make-symbol "list")))
+    `(let ((,l ,list))
+       (while ,l
+         (let ((it (car ,l)))
+           ,form)
+         (setq ,l (cdr ,l))))))
+
+(defun -each (list fn)
+  "Calls FN with every item in LIST. Returns nil, used for side-effects only."
+  (--each list (funcall fn it)))
+
 (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)
@@ -353,56 +411,6 @@ or with `-compare-fn' if that's non-nil."
 To get the first item in the list no questions asked, use `car'."
   (--first (funcall fn it) list))
 
-(defun ---truthy? (val)
-  (not (null val)))
-
-(defmacro --any? (form list)
-  "Anaphoric form of `-any?'."
-  `(---truthy? (--first ,form ,list)))
-
-(defun -any? (fn list)
-  "Returns t if (FN x) is non-nil for any x in LIST, else nil.
-
-Alias: `-some?'"
-  (--any? (funcall fn it) list))
-
-(defalias '-some? '-any?)
-(defalias '--some? '--any?)
-
-(defmacro --all? (form list)
-  "Anaphoric form of `-all?'."
-  (let ((l (make-symbol "list"))
-        (a (make-symbol "all")))
-    `(let ((,l ,list)
-           (,a t))
-       (while (and ,a ,l)
-         (let ((it (car ,l)))
-           (setq ,a ,form))
-         (setq ,l (cdr ,l)))
-       (---truthy? ,a))))
-
-(defun -all? (fn list)
-  "Returns t if (FN x) is non-nil for all x in LIST, else nil.
-
-Alias: `-every?'"
-  (--all? (funcall fn it) list))
-
-(defalias '-every? '-all?)
-(defalias '--every? '--all?)
-
-(defmacro --each (list form)
-  "Anaphoric form of `-each'."
-  (let ((l (make-symbol "list")))
-    `(let ((,l ,list))
-       (while ,l
-         (let ((it (car ,l)))
-           ,form)
-         (setq ,l (cdr ,l))))))
-
-(defun -each (list fn)
-  "Calls FN with every item in LIST. Returns nil, used for side-effects only."
-  (--each list (funcall fn it)))
-
 (defvar -compare-fn nil
   "Tests for equality use this function or `equal' if this is nil.
 It should only be set using dynamic scope with a let, like:
diff --git a/examples.el b/examples.el
index 4f1acf2..c6b5a5b 100644
--- a/examples.el
+++ b/examples.el
@@ -62,6 +62,27 @@
   (-mapcat (lambda (item) (list 0 item)) '(1 2 3)) => '(0 1 0 2 0 3)
   (--mapcat (list 0 it) '(1 2 3)) => '(0 1 0 2 0 3))
 
+(defexamples -any?
+  (-any? 'even? '(1 2 3)) => t
+  (-any? 'even? '(1 3 5)) => nil
+  (--any? (= 0 (% it 2)) '(1 2 3)) => t)
+
+(defexamples -all?
+  (-all? 'even? '(1 2 3)) => nil
+  (-all? 'even? '(2 4 6)) => t
+  (--all? (= 0 (% it 2)) '(2 4 6)) => t)
+
+(defexamples -none?
+  (-none? 'even? '(1 2 3)) => nil
+  (-none? 'even? '(1 3 5)) => t
+  (--none? (= 0 (% it 2)) '(1 2 3)) => nil)
+
+(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)
+  (let (s) (--each '(1 2 3) (setq s (cons it s))) s) => '(3 2 1)
+  (let (s) (--each (reverse (three-letters)) (setq s (cons it s))) s) => '("A" 
"B" "C"))
+
 (defexamples -take
   (-take 3 '(1 2 3 4 5)) => '(1 2 3)
   (-take 17 '(1 2 3 4 5)) => '(1 2 3 4 5))
@@ -132,22 +153,6 @@
   (-contains? '() 1) => nil
   (-contains? '() '()) => nil)
 
-(defexamples -any?
-  (-any? 'even? '(1 2 3)) => t
-  (-any? 'even? '(1 3 5)) => nil
-  (--any? (= 0 (% it 2)) '(1 2 3)) => t)
-
-(defexamples -all?
-  (-all? 'even? '(1 2 3)) => nil
-  (-all? 'even? '(2 4 6)) => t
-  (--all? (= 0 (% it 2)) '(2 4 6)) => 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)
-  (let (s) (--each '(1 2 3) (setq s (cons it s))) s) => '(3 2 1)
-  (let (s) (--each (reverse (three-letters)) (setq s (cons it s))) s) => '("A" 
"B" "C"))
-
 (defexamples -partial
   (funcall (-partial '- 5) 3) => 2
   (funcall (-partial '+ 5 2) 3) => 10)



reply via email to

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