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

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

[elpa] externals/dash 0991c29 057/426: Added some common aliases


From: Phillip Lord
Subject: [elpa] externals/dash 0991c29 057/426: Added some common aliases
Date: Tue, 04 Aug 2015 19:36:41 +0000

branch: externals/dash
commit 0991c29e84a3fb18861c6644693d0c0ca126875e
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>

    Added some common aliases
    
     - also removed mention of clojure, since we're departing from that API
---
 README.md          |   36 +++++++++++++++++++++---------------
 bang.el            |   51 +++++++++++++++++++++++++++++++++++++--------------
 examples.el        |   18 +++++++++---------
 readme-template.md |    4 +---
 4 files changed, 68 insertions(+), 41 deletions(-)

diff --git a/README.md b/README.md
index e8855bd..0eeae9e 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,6 @@
 # bang.el [![Build 
Status](https://secure.travis-ci.org/magnars/bang.el.png)](http://travis-ci.org/magnars/bang.el)
 
-The startings of a modern list api for Emacs. Does not require 'cl.
-
-We're looking to Clojure for naming and signatures.
+The startings of a modern list api for Emacs that does not require 'cl.
 
 ## Warning
 
@@ -23,8 +21,8 @@ This is so much a work in progress that you should definitely 
not be using it ye
 * [!intersection](#intersection-list-list2) `(list list2)`
 * [!distinct](#distinct-list) `(list)`
 * [!contains?](#contains-list-element) `(list element)`
-* [!some](#some-fn-list) `(fn list)`
-* [!every?](#every-fn-list) `(fn list)`
+* [!any?](#any-fn-list) `(fn list)`
+* [!all?](#all-fn-list) `(fn list)`
 * [!each](#each-list-fn) `(list fn)`
 
 There are also anaphoric versions of these functions where that makes sense,
@@ -101,6 +99,8 @@ exposed as `acc`.
 
 Returns a new list of the items in `list` for which `fn` returns a non-nil 
value.
 
+Alias: `!select`
+
 ```cl
 (!filter (lambda (num) (= 0 (% num 2))) '(1 2 3 4)) ;; => '(2 4)
 (!filter 'even? '(1 2 3 4)) ;; => '(2 4)
@@ -111,6 +111,8 @@ Returns a new list of the items in `list` for which `fn` 
returns a non-nil value
 
 Returns a new list of the items in `list` for which `fn` returns nil.
 
+Alias: `!reject`
+
 ```cl
 (!remove (lambda (num) (= 0 (% num 2))) '(1 2 3 4)) ;; => '(1 3)
 (!remove 'even? '(1 2 3 4)) ;; => '(1 3)
@@ -208,24 +210,28 @@ or with `!compare-fn` if that's non-nil.
 (!contains? '(1 2 3) 4) ;; => nil
 ```
 
-### !some `(fn list)`
+### !any? `(fn list)`
 
-Returns the first non-nil value of (`fn` x) for any x in `list`, else nil.
+Returns t if (`fn` x) is non-nil for any x in `list`, else nil.
+
+Alias: `!some?`
 
 ```cl
-(!some 'even? '(1 2 3)) ;; => t
-(!some 'even? '(1 3 5)) ;; => nil
-(!!some (= 0 (% it 2)) '(1 2 3)) ;; => t
+(!any? 'even? '(1 2 3)) ;; => t
+(!any? 'even? '(1 3 5)) ;; => nil
+(!!any? (= 0 (% it 2)) '(1 2 3)) ;; => t
 ```
 
-### !every? `(fn list)`
+### !all? `(fn list)`
+
+Returns t if (`fn` x) is non-nil for all x in `list`, else nil.
 
-Returns t if (`fn` x) is non-nil for every x in `list`, else nil.
+Alias: `!every?`
 
 ```cl
-(!every? 'even? '(1 2 3)) ;; => nil
-(!every? 'even? '(2 4 6)) ;; => t
-(!!every? (= 0 (% it 2)) '(2 4 6)) ;; => t
+(!all? 'even? '(1 2 3)) ;; => nil
+(!all? 'even? '(2 4 6)) ;; => t
+(!!all? (= 0 (% it 2)) '(2 4 6)) ;; => t
 ```
 
 ### !each `(list fn)`
diff --git a/bang.el b/bang.el
index 1aedf30..17ed950 100644
--- a/bang.el
+++ b/bang.el
@@ -85,17 +85,27 @@ exposed as `acc`."
      (nreverse !--result)))
 
 (defun !filter (fn list)
-  "Returns a new list of the items in LIST for which FN returns a non-nil 
value."
+  "Returns a new list of the items in LIST for which FN returns a non-nil 
value.
+
+Alias: `!select'"
   (!!filter (funcall fn it) list))
 
+(defalias '!select '!filter)
+(defalias '!!select '!!filter)
+
 (defmacro !!remove (form list)
   "Anaphoric form of `!remove'."
   `(!!filter (not ,form) ,list))
 
 (defun !remove (fn list)
-  "Returns a new list of the items in LIST for which FN returns nil."
+  "Returns a new list of the items in LIST for which FN returns nil.
+
+Alias: `!reject'"
   (!!remove (funcall fn it) list))
 
+(defalias '!reject '!remove)
+(defalias '!!reject '!!remove)
+
 (defmacro !!keep (form list)
   "Anaphoric form of `!keep'."
   `(let ((!--list ,list)
@@ -168,33 +178,46 @@ or with `!compare-fn' if that's non-nil."
           (setq lst (cdr lst)))
         lst))))))
 
-(defmacro !!some (form list)
-  "Anaphoric form of `!some'."
+(defun !--truthy? (val)
+  (not (null val)))
+
+(defmacro !!any? (form list)
+  "Anaphoric form of `!any?'."
   `(let ((!--list ,list)
          (!--any nil))
      (while (and !--list (not !--any))
        (let ((it (car !--list)))
          (setq !--any ,form))
        (setq !--list (cdr !--list)))
-     !--any))
+     (!--truthy? !--any)))
 
-(defun !some (fn list)
-  "Returns the first non-nil value of (FN x) for any x in LIST, else nil."
-  (!!some (funcall fn it) list))
+(defun !any? (fn list)
+  "Returns t if (FN x) is non-nil for any x in LIST, else nil.
 
-(defmacro !!every? (form list)
-  "Anaphoric form of `!every?'."
+Alias: `!some?'"
+  (!!any? (funcall fn it) list))
+
+(defalias '!some? '!any?)
+(defalias '!!some? '!!any?)
+
+(defmacro !!all? (form list)
+  "Anaphoric form of `!all?'."
   `(let ((!--list ,list)
          (!--all t))
      (while (and !--all !--list)
        (let ((it (car !--list)))
          (setq !--all ,form))
        (setq !--list (cdr !--list)))
-     (not (null !--all))))
+     (!--truthy? !--all)))
+
+(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))
 
-(defun !every? (fn list)
-  "Returns t if (FN x) is non-nil for every x in LIST, else nil."
-  (!!every? (funcall fn it) list))
+(defalias '!every? '!all?)
+(defalias '!!every? '!!all?)
 
 (defmacro !!each (list form)
   "Anaphoric form of `!each'."
diff --git a/examples.el b/examples.el
index df6ae81..a79d095 100644
--- a/examples.el
+++ b/examples.el
@@ -81,15 +81,15 @@
   (!contains? '() 1) => nil
   (!contains? '() '()) => nil)
 
-(defexamples !some
-  (!some 'even? '(1 2 3)) => t
-  (!some 'even? '(1 3 5)) => nil
-  (!!some (= 0 (% it 2)) '(1 2 3)) => t)
-
-(defexamples !every?
-  (!every? 'even? '(1 2 3)) => nil
-  (!every? 'even? '(2 4 6)) => t
-  (!!every? (= 0 (% it 2)) '(2 4 6)) => t)
+(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
diff --git a/readme-template.md b/readme-template.md
index 29900ce..9e0cc9f 100644
--- a/readme-template.md
+++ b/readme-template.md
@@ -1,8 +1,6 @@
 # bang.el [![Build 
Status](https://secure.travis-ci.org/magnars/bang.el.png)](http://travis-ci.org/magnars/bang.el)
 
-The startings of a modern list api for Emacs. Does not require 'cl.
-
-We're looking to Clojure for naming and signatures.
+The startings of a modern list api for Emacs that does not require 'cl.
 
 ## Warning
 



reply via email to

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