[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash ba60707 103/426: Use --each-while to simplify impl
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash ba60707 103/426: Use --each-while to simplify implementations. |
Date: |
Tue, 04 Aug 2015 19:37:00 +0000 |
branch: externals/dash
commit ba607079bd81719ab7b08e21b0ac34127e4b1d85
Author: Magnar Sveen <address@hidden>
Commit: Magnar Sveen <address@hidden>
Use --each-while to simplify implementations.
---
dash.el | 34 ++++++++++------------------------
1 files changed, 10 insertions(+), 24 deletions(-)
diff --git a/dash.el b/dash.el
index 3c38370..0a167ce 100644
--- a/dash.el
+++ b/dash.el
@@ -167,17 +167,11 @@ Alias: `-reject'"
Thus function FN should return a collection."
(--mapcat (funcall fn it) list))
-;; can be simplified with an --each that stops at a predicate, --each-while?
(defmacro --first (form list)
"Anaphoric form of `-first'."
- (let ((l (make-symbol "list"))
- (n (make-symbol "needle")))
- `(let ((,l ,list)
- (,n nil))
- (while (and ,l (not ,n))
- (let ((it (car ,l)))
- (when ,form (setq ,n it)))
- (!cdr ,l))
+ (let ((n (make-symbol "needle")))
+ `(let (,n)
+ (--each-while ,list (not ,n) (when ,form (setq ,n it)))
,n)))
(defun -first (fn list)
@@ -209,14 +203,9 @@ Alias: `-some?'"
(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))
- (!cdr ,l))
+ (let ((a (make-symbol "all")))
+ `(let ((,a t))
+ (--each-while ,list ,a (setq ,a ,form))
(---truthy? ,a))))
(defun -all? (fn list)
@@ -244,6 +233,7 @@ Alias: `-every?'"
(defalias '-none-p '-none?)
(defalias '--none-p '--none?)
+;; simplify with a --dotimes
(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)
@@ -262,13 +252,9 @@ Alias: `-every?'"
(defmacro --take-while (form list)
"Anaphoric form of `-take-while'."
- (let ((l (make-symbol "list"))
- (r (make-symbol "result")))
- `(let ((,l ,list)
- (,r '()))
- (while (and ,l (let ((it (car ,l))) ,form))
- (!cons (car ,l) ,r)
- (!cdr ,l))
+ (let ((r (make-symbol "result")))
+ `(let (,r)
+ (--each-while ,list ,form (!cons it ,r))
(nreverse ,r))))
(defun -take-while (fn list)
- [elpa] externals/dash 79b56cc 101/426: Use --each, !cons and !cdr to simplify implementations., (continued)
- [elpa] externals/dash 79b56cc 101/426: Use --each, !cons and !cdr to simplify implementations., Phillip Lord, 2015/08/04
- [elpa] externals/dash a08fc14 102/426: Add -each-while, Phillip Lord, 2015/08/04
- [elpa] externals/dash 49512b9 107/426: Simplify -take and -drop with --dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash ed47814 105/426: Add -dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash eb50d17 106/426: Add Melpa back in., Phillip Lord, 2015/08/04
- [elpa] externals/dash 0e5c69b 089/426: Docs: more concise example for anaphoric functions., Phillip Lord, 2015/08/04
- [elpa] externals/dash 03370ea 108/426: Simplify examples-to-docs and examples-to-tests with dash, Phillip Lord, 2015/08/04
- [elpa] externals/dash ba80875 109/426: Nice indentation for --each, --each-while and --dotimes, Phillip Lord, 2015/08/04
- [elpa] externals/dash f1c8453 083/426: Rename to dash., Phillip Lord, 2015/08/04
- [elpa] externals/dash 51ddc13 110/426: Nice indentation for threading macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash ba60707 103/426: Use --each-while to simplify implementations.,
Phillip Lord <=
- [elpa] externals/dash c56925a 111/426: Add font-lock for new functions and the `it` token., Phillip Lord, 2015/08/04
- [elpa] externals/dash a081c72 114/426: Fix tests., Phillip Lord, 2015/08/04
- [elpa] externals/dash a336d78 112/426: Add -only-some?, Phillip Lord, 2015/08/04
- [elpa] externals/dash 81a3247 104/426: Let -each and -each-while take multiple forms., Phillip Lord, 2015/08/04
- [elpa] externals/dash d857f73 118/426: Merge pull request #3 from rejeep/join-alias, Phillip Lord, 2015/08/04
- [elpa] externals/dash 9faa422 115/426: Add -partition-by, Phillip Lord, 2015/08/04
- [elpa] externals/dash f034c16 119/426: Add -union (thanks to @Fuco1), Phillip Lord, 2015/08/04
- [elpa] externals/dash 9a3dfdd 113/426: Name parameter PRED when function expects predicate., Phillip Lord, 2015/08/04
- [elpa] externals/dash cca9b1b 121/426: Also run tests on Emacs24, Phillip Lord, 2015/08/04
- [elpa] externals/dash c669282 123/426: Add @Fuco1 to list of contributors., Phillip Lord, 2015/08/04